Grayside.Org - views http://grayside.org/category/terms/views en Infinite Null: Sorting NULL to Last http://grayside.org/2011/08/infinite-null-sorting-null-last <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p><em>Please, keep in mind this post was written for Drupal 6 and Views 2! D7/Views 3 sites might not take so kindly to it.</em></p> <p>Recently I was looking at creating a new Todo Feature with a due date. I cracked open <span class="caps">CCK</span>’s <em>manage fields</em> <span class="caps">UI</span> and added a date field, careful to keep in mind that the default value should be <strong>no date</strong>, which just happens to translate as <span class="caps">NULL</span>. You see, for my Todo use case, not all Todos would have a deadline.</p> <p>My next step was to create a View of all upcoming items. I wanted the next most urgent todo to float to the top of the list. Sadly, <span class="caps">NULL</span> counts as 0 in database land, so my carefully clicked Sort was preloading all my urgent todos with all the lowest priority tasks.</p> <p>Seeing as this was a <span class="caps">SQL</span> problem, I googled the ‘net for viable query tweaks. I found a nice article illustrating exactly what I wanted: <a href="http://www.shawnolson.net/a/730/mysql_sort_order_with_null.html">MySQL Sort Order with <span class="caps">NULL</span></a>. The grand secret? Sort first by whether the duedate is <span class="caps">NULL</span> to flip your empty values to the bottom of the result set.</p> <p>The fastest way for me to apply this tweak to my feature was to hack the Views query. <code>hook_views_query_alter()</code> is usually a horrible decision. Once you’ve put it into code, tweaking your View a lot around your alteration can quickly result in a broken query. Meanwhile:</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #009933; font-style: italic;">/** &nbsp;* Implementation of hook_views_query_alter(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> example_views_query_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$view</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'example_listing'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <a href="http://www.php.net/array_unshift"><span style="color: #990000;">array_unshift</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderby</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'<span class="caps">ISNULL</span>(node_data_field_duedate_field_duedate_value) <span class="caps">ASC</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>(For a longer use case on this Views bandaid, see <a href="http://btmash.com/article/2011-06-09/correcting-views-queries-using-views-query-alter">Correcting views queries using views_query_alter</a>)</p> <p>I arrived here by turning on the <a href="http://drupal.org/project/devel">Devel</a> module, and dropping a <code>dpm($query)</code> into that function first thing. This gave me the array structure of my View, including the various <span class="caps">SQL</span> entries for the <span class="caps">ORDER</span> <span class="caps">BY</span> arguments. A quick and dirty <code>array_unshift()</code> forces the <span class="caps">NULL</span> check for my date field (the alias I also found in the $query object, there are more elegant methods) onto the top of the ordering hierarchy.</p> <p>Bingo! <span class="caps">NULL</span>-dated nodes are sorted to&nbsp;last.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/1/sql">sql</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/1/views2">views2</a></div><div class="field-item odd"><a href="/taxonomy/term/1">drupal</a></div></div></div> Thu, 25 Aug 2011 04:01:43 +0000 Grayside 94 at http://grayside.org http://grayside.org/2011/08/infinite-null-sorting-null-last#comments How to Override a Views Field Template from a Module http://grayside.org/2010/09/how-override-views-field-template-module <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Some months ago I wanted the solution to overriding a Views Field template entirely from within a module. I spent hours trawling documentation and issues, and playing with a little trial and error. In the end, I came up with a solution:</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #009933; font-style: italic;">/** &nbsp;* Implementation of hook_theme(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_module_theme<span style="color: #009900;">&#40;</span><span style="color: #000088;">$existing</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> &nbsp; &nbsp; <span style="color: #0000ff;">'views_view_field__view_name__field_name'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'arguments'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'field'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'row'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'template'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'views-view-field--view-name--field-name'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'original hook'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'views_view_field'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> drupal_get_path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'module'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'custom_module'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/theme'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>By defining a Views template in this way, you are doing the equivalent to building your template and dropping it into your Theme&#8217;s directory. This is sufficient for Views to notice the existence of the template from within your module. At that point the standard Views logic of finding the most specific template available for each field comes into play. In this case, every instance of <em>field name</em> in <em>view name</em> will use this template&#8230; unless, of course, I have a more specific template somewhere that targets that field in a specific display.</p> <p>Note that the theme key and template name are the same, but for the swapping of hyphens and underscores. The way both of those are named is critical, else Views will not properly notice the template. All the options listed in <strong>Theme Information</strong> in the Views <span class="caps">UI</span> is available for use here.</p> <p>Note that this is very derivative of the hard work of others, and I will link to it here when I come across it again.</p> <p><strong><a href="http://drupal.org/node/627378">views template overrides in module directory</a> was one of my key references. Since I checked that thread, the marvelous @dereine posted a patch with the intent to guide Views to find theme templates in module directories as well. It <em>Needs Review</em>, so if the code above bores you, go review the&nbsp;patch!</strong></p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/theming">theming</a></div></div></div> Wed, 15 Sep 2010 21:07:05 +0000 Grayside 90 at http://grayside.org http://grayside.org/2010/09/how-override-views-field-template-module#comments Adding a Content Type to the Open Atrium Calendar Views http://grayside.org/2010/09/adding-content-type-open-atrium-calendar-views <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>People often seem to wonder how they can get their new date-specified content types to show up on the Atrium Calendar. The following Views snippet makes it happen for a content type called &#8220;example_type&#8221; in module &#8220;custom&#8221;. Note that this code is specific to the Views as they were renamed for <a href="http://drupal.org/project/kit">Kit</a>-compatibility in Open Atrium 1.0-beta8.</p> <h3>Step 1</h3> <p>Build your &#8220;example_type&#8221; content type. You can build this out however you want, but for the purpose of this post you need to add the same <em>field_date</em> that the Event type uses.</p> <h3>Step 2</h3> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #009933; font-style: italic;">/** &nbsp;* Implementation of hook_views_default_views_alter(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_views_default_views_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$views</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$views</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'calendar_listing'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'example_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'example_type'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$views</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'calendar_upcoming'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'example_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'example_type'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <h2>Why Not Override the View with Views <span class="caps">UI</span>?</h2> <p>Once you have overridden the core Views in Atrium, you take a potentially stressful upgrade/maintenance path and make it vaguely nightmarish. Your changes will disappear into the ether when you upgrade. Restoring your changes would require building out a site based on a backup database to grab the key pieces of your override.</p> <p>By keeping these changes in code, you can much more easily determine how to fix them&#8230; assuming any changes are even necessary!</p> <p>Happy calendar&nbsp;hooking.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/openatrium">openatrium</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/calendar">calendar</a></div></div></div> Wed, 08 Sep 2010 23:04:50 +0000 Grayside 89 at http://grayside.org http://grayside.org/2010/09/adding-content-type-open-atrium-calendar-views#comments Optional Spaces Integration for a View http://grayside.org/2010/06/optional-spaces-integration-view <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>If you want to make an exported [node-based] View smoothly integrate with Spaces, you can use the following code to modify the View structure with the &#8220;Content in current space&#8221; filter. This filter does nothing if the View is not itself in a Space, otherwise it restricts all results to content in the same space. Add any conditions you want to control whether the Spaces integration is applied.</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #009933; font-style: italic;">/** &nbsp;* Implementation of hook_views_default_views_alter(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_views_default_views_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$views</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>module_exists<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'spaces'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #000088;">$views</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'view_name_here'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'current'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'operator'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'all'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'group'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'exposed'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">FALSE</span></span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'expose'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'operator'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">FALSE</span></span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'current'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'spaces'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'field'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'current'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'relationship'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'none'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>If you would like to take it a step further, and create OpenAtrium features integration, insert the following:</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal"><span style="color: #000088;">$views</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'view_name_here'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">display_options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> &nbsp; <span style="color: #0000ff;">'type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'atrium_feature'</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000ff;">'spaces_feature'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'feature_name'</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #0000ff;">'perm'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'access content'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// or any other permission</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div> </div> <p>hook_views_default_views_alter() fires off before the View is cached, so be sure to clear your cache after adding this code to see the results.</p> <p>This code snippet is a finding from my work on <a href="http://grayside.org/2010/06/integrating-features-server-openatrium">OpenAtrium-FeatureServer&nbsp;integration</a>.</p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/spaces">spaces</a></div></div></div> Tue, 15 Jun 2010 21:05:02 +0000 Grayside 82 at http://grayside.org http://grayside.org/2010/06/optional-spaces-integration-view#comments Changing Node Group Audience http://grayside.org/2010/04/changing-node-group-audience <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>In OpenAtrium, it&#8217;s not easy to change the group affiliation of a node once it has been created. <span class="caps">OA</span> locks down the interface to set group audience specifically to make the interface easier to understand.</p> <p>I have just posted a quick feature that demonstrates how to grant administrators the ability to shuffle nodes around between groups, it can be found in the <a href="https://community.openatrium.com/issues/node/48#comment-3624">issue queue at community.<span class="caps">OA</span></a>.</p> <p>It introduces two things&#8211;a new Action that toggles the group audience of a given node, and a <a href="http://drupal.org/project/views_bulk_operations">Views Bulk Operations</a> View that allows you to apply that action to batches.</p> <p>There is a special column in the View labeled &#8220;Member of Private Group&#8221;. This column lets the administrator know whether the current group is a private group, meaning the content is almost certainly private as well. Any quality of the group a node starts in will be lost once you move a node to a new group, and that includes whether it is private content. Remember that, and use with care!</p> <p>Note: If you preface the <span class="caps">URL</span> of the View with a group namespace, it will limit the content to the nodes of that group.</p> <p><strong>Download feature from my Features Server&nbsp;<a href="http://tinkercms.grayside.org/projects/atrium-groups-change-node-group">here</a></strong></p> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/openatrium">openatrium</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/og">og</a></div><div class="field-item odd"><a href="/category/terms/vbo">vbo</a></div><div class="field-item even"><a href="/category/terms/actions">actions</a></div></div></div> Mon, 12 Apr 2010 18:33:31 +0000 Grayside 62 at http://grayside.org http://grayside.org/2010/04/changing-node-group-audience#comments OpenAtrium Empty Views: Gimme That Button! http://grayside.org/2010/03/openatrium-empty-views-gimme-button <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Do you like the large gray &#8220;Add Blog entry&#8221; button when you first visit your blog space, and have yet to create anything? Creating views with similar buttons (or adding more) is really easy!</p> <p>The key is to create <strong>Empty text</strong> in your view using the <em>Full <span class="caps">HTML</span></em> Input Format. Then, drop some <span class="caps">HTML</span> in like this to make use of Atrium&#8217;s built-in theming.</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">&lt;div class=&quot;buttons&quot;&gt; &nbsp; &lt;ul class=&quot;links&quot;&gt; &nbsp; &nbsp; &lt;li class=&quot;first last&quot;&gt; &nbsp; &nbsp; &nbsp; &lt;a href=&quot;/node/add/blog&quot;&gt;Add Blog entry&lt;/a&gt; &nbsp; &nbsp; &lt;/li&gt; &nbsp; &lt;/ul&gt; &lt;/div&gt;</pre></div> </div> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/category/terms/openatrium">openatrium</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/theming">theming</a></div><div class="field-item odd"><a href="/category/terms/snippets">snippets</a></div></div></div> Sat, 06 Mar 2010 17:28:14 +0000 Grayside 56 at http://grayside.org http://grayside.org/2010/03/openatrium-empty-views-gimme-button#comments Public Facing Site through Secured Syndication http://grayside.org/2009/12/public-facing-site-through-secured-syndication <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>When you need to stack content access mechanisms together in Drupal, things can get pretty messy. When you add <a href="http://drupal.org/project/og">Organic Groups</a> to the mix, it gets pretty wild. I&#8217;ve been faced more than once with the challenge of building a site that would be 90% internal, and 10% public. Unfortunately, than 10% of public content represents 50% of the site&#8217;s complexity, especially when configuring around the settings and functionality required for a nice Intranet.</p> <p>I hate to bow out from the challenge, but in this morass, there is no clean and quick answer. The best solution might be the easiest. How about content syndication?</p> <p>Half the challenge here is to allow internal users to create and view all the content they care about in the same place. On occasion, content is created that is at least partially for public consumption. Rather than send content creators (and interested internal personnel) off to a site not meant for them, how about setting up a completely separate, public-facing site. One that emphasizes public information, and pulls it&#8217;s primary content from the internal site?</p> <p>The only problem is how we get around that access complication so this other site can read the feed.</p> <p>I have one recipe that (mostly) works, and one I have yet to try.</p> <h3>Tokenauth</h3> <ol> <li>Install the <a href="http://drupal.org/project/tokenauth">Token Authentication</a> module. Tokenauth is a nifty module that maintains the assignment of an alphanumeric token to every user of your site. With that token appended to a <span class="caps">URL</span>, it will operate as a one-off login. This would be frightening for security, except the pages accessible in this way are also configured, after the fashion of block visibility path settings.</li> <li>Configure the allowed paths to a single content export root path. For example, <code>public/*</code> or <code>export/*</code>.</li> <li>Install the <a href="http://drupal.org/project/flag">Flag</a> module. Create a flag attached to all the content types whose content you may want to expose, and label this flag &#8220;Make it Public&#8221;.</li> <li>Create a View. Create a <em>Relationship</em> on the flag you built in Step 3, and <strong>Require</strong> it. Create a Feed display. Set the path to <code>public</code>. And save.</li> <li>Create a fake user with legitimate access to view the content. If possible, make sure the only access this account has, is viewing that content. Take note of the tokenauth token assigned to this user.</li> <li>Build your public website.&nbsp;7.</li> </ol> </div></div></div><div class="field field-name-taxonomy-vocabulary-1 field-type-taxonomy-term-reference field-label-above"><div class="field-label">Terms:&nbsp;</div><div class="field-items"><div class="field-item even"><a href="/taxonomy/term/1">drupal</a></div><div class="field-item odd"><a href="/category/terms/tokenauth">tokenauth</a></div><div class="field-item even"><a href="/category/terms/flag">flag</a></div><div class="field-item odd"><a href="/category/terms/views">views</a></div><div class="field-item even"><a href="/category/terms/access-control">access control</a></div><div class="field-item odd"><a href="/category/terms/feeds">feeds</a></div><div class="field-item even"><a href="/category/terms/rss">rss</a></div><div class="field-item odd"><a href="/category/terms/web-service-clients">web service clients</a></div></div></div> Tue, 08 Dec 2009 01:06:05 +0000 Grayside 52 at http://grayside.org