Grayside.Org's Syndication Island http://grayside.org/feed/drupal-planet/rss.xml en Release: Organic Groups 6.x-2.3 http://grayside.org/2012/03/release-organic-groups-6x-23 <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Today was the release of <span class="caps">OG</span> 6, Version 2.3</p> <p>We have a fine assortment of changes (see the <a href="http://drupal.org/node/1507328">changelog</a>), ranging across:</p> <ul> <li>Extensive og.module commenting.</li> <li>Views integration improvements.</li> <li>Many &#8220;<span class="caps">OG</span>, what are you thinking?&#8221; bugfixes.</li> <li>And even some performance enhancements.</li> </ul> <p>This release covers three classes of issues:</p> <ul> <li>The remaining low hanging fruit languishing in the issue queue over the last two years.</li> <li>Lowish-hanging fruit that I had the time to finish myself.</li> <li>Development of enhancements and bugfixes I ran into during the work hours.</li> </ul> <p>As I presented last time, I have a bit of a <a href="http://groups.drupal.org/node/196863">manifesto on how I&#8217;m approaching changes to <span class="caps">OG6</span></a>. Unusual levels of conservatism have led to such oddities in a Drupal project as a function with a @deprecated tag.</p> <p>There are still items in progress in the issue queue, but since most everyone has moved on to the fantastic Drupal 7 version of Organic Groups, there are very few people contributing their efforts. That&#8217;s fine, but you can start to expect most changes to <span class="caps">OG6</span> to come by way of my own itches. I don&#8217;t use Notifications, I don&#8217;t use multi-group posting, I don&#8217;t use the audience widget. If you care about these things, please help the many people that share your plight and present some patches and reviews <a href="http://drupal.org/project/issues/og?version=6.x">in the&nbsp;queue</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="/category/terms/drupal6">drupal6</a></div><div class="field-item odd"><a href="/category/terms/organic-groups">organic groups</a></div></div></div> Wed, 28 Mar 2012 21:27:05 +0000 Grayside 97 at http://grayside.org http://grayside.org/2012/03/release-organic-groups-6x-23#comments Release: Organic Groups 6.x-2.2 http://grayside.org/2012/01/release-organic-groups-6x-22 <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I have just tagged the first <span class="caps">OG6</span> release since March of 2010.</p> <p>We have a fine assortment of changes (see the <a href="http://drupal.org/node">changelog</a>), ranging across:</p> <ul> <li>New Hook <span class="caps">API</span> Documentation</li> <li>Views integration improvements</li> <li>Localization improvements</li> <li>Miscellaneous areas of moderate interest</li> </ul> <p>This release locks in some changes, clarifies the status of Notifications (sticking with the 2.x line for now), and sets up <span class="caps">OG6</span> for a stable position to start looking at what should happen next. I&#8217;ve posted a sort of maintainer&#8217;s philosophy position on how I see <span class="caps">OG6</span> moving forward, you can read it at the <a href="http://groups.drupal.org/node/196863">d.g.o address of Organic Groups</a>. What does all that translate into for my next steps?</p> <p>Well, aside from a few clear cases, it&#8217;s still very much up to the community. I&#8217;m going to focus on a few good patches, and see if I can help the <a href="http://drupal.org/project/issues/search/og?text=&amp;assigned=&amp;submitted=&amp;participant=&amp;status%5B%5D=Open&amp;issue_tags_op=or&amp;issue_tags=gdolove">groups.drupal.org-related issues</a>, <a href="http://drupal.org/project/issues/search/og?text=&amp;assigned=&amp;submitted=&amp;participant=&amp;status%5B%5D=Open&amp;issue_tags_op=or&amp;issue_tags=performance">performance</a>, and <a href="http://drupal.org/project/issues/search/og?text=&amp;assigned=&amp;submitted=&amp;participant=&amp;status%5B%5D=Open&amp;issue_tags_op=or&amp;issue_tags=og-wtf">the Weirdness</a> subqueues. I&#8217;m hoping to have enough cool stuff pulled together to release 2.3 in honor of Drupalcon&nbsp;Denver.</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/drupal6">drupal6</a></div><div class="field-item odd"><a href="/category/terms/organic-groups">organic groups</a></div></div></div> Fri, 13 Jan 2012 19:16:45 +0000 Grayside 95 at http://grayside.org http://grayside.org/2012/01/release-organic-groups-6x-22#comments 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 Configure Drush in Your Git Repository http://grayside.org/2011/08/configure-drush-your-git-repository <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>One of the neat features of Drush is it&#8217;s configurability. Setting the defaults for various behaviors and command options allows you to build really simplified, specialized workflows. You can create personal settings defaults by dropping a `drushrc.php` file in one of the places Drush will look, such as inside a .drush folder of your home&nbsp;directory.</p> <p>It turns out this little capability has provided some very simple wins for developers at <a href="http://www.goingon.com">GoingOn</a>. We pass around our projects and sites as a subdirectory of a Git repository that contains various things, such as documentation, deployment tools, and drush commands. Unfortunately, this slightly irregular practice disconnects Drush from the Drupal site and excludes those drush commands from the standard directories drush&nbsp;scans.</p> <p>We fix this by making Drush aware of the Git Repo. There is a command-line script you can use to check if you are anywhere in a Git repository. By configuring Drush to check for a Git Repo on every drush bootstrapping, we give Drush a chance to pick up a bonus, repository-specific Drush config&nbsp;file.</p> <p><em>Add this snippet to your drushrc.php&nbsp;file:</em></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;">$output</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <a href="http://www.php.net/exec"><span style="color: #990000;">exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'git rev-parse --show-toplevel 2&gt; /dev/null'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$repo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'config'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/drushrc.php'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'include'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/commands'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'alias-path'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$repo</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/drush/aliases'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>This script checks the current directory for participation in a git repository. If there is one, it looks at the root of the git repository for a &#8216;.drushrc.php&#8217; file to provide repo-specific instructions to Drush. We use this to configure paths to external resources that can vary by code version, as well as setting the Drupal site root for the Drupal site sihpped with that particular&nbsp;repository.</p> <p>The last line also seeks out a `scripts/` directory in the repository root, which it will scan recursively for any files ending in `.drush.inc`. This allows us to ship versioned drush commands with each repo instead of documenting a complex individual installation&nbsp;process.</p> <p>There are many other things you can do with a little poking about in the options for a drushrc file, to learn more start with the <a href="http://drush.ws/examples/example.drushrc.php">drushrc.php example</a>.</p> <p><strong>Update 7/16/2012</strong>: Updated code example to the same provided in Drush docs. You can now leverage this trick outside the root directory of your code repository. Also removed not applicable git context resulting in invalid configuration&nbsp;paths.</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/drush">drush</a></div><div class="field-item even"><a href="/taxonomy/term/86">git</a></div></div></div> Sat, 20 Aug 2011 06:53:18 +0000 Grayside 93 at http://grayside.org http://grayside.org/2011/08/configure-drush-your-git-repository#comments D7 Upgrade Process: Backports to Close the Gap http://grayside.org/2011/08/d7-upgrade-process-backports-close-gap <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>The following post originally appeared on the <a href="http://goingon.com/blog/d7-upgrade-process-backports-close-gap">GoingOn.com blog</a>.</em></p> <p>After more than a year of continuous investment in <a href="http://goingon.com">GoingOn</a>&#8217;s Drupal 6 platform, the idea of upgrading to Drupal 7 is incredibly daunting. We have custom modules from form behaviors down to the access layer, we have features encapsulating hundreds of exported components, and an aggressive feature release schedule that does not set aside 6 months for a complete rewrite of the codebase just for a new version of Drupal. What to&nbsp;do?</p> <p>We’ve been playing around with the idea of iterating our Drupal 6 platform toward Drupal 7. By pulling markup, design patterns, APIs, and architecture in Drupal 7 down into platform incrementally, we hope to shorten the final leap that will come when upgrading the entire&nbsp;system.</p> <h5>Driving Current Drupal Version Closer to Expected Drupal&nbsp;Version</h5> <p><img src="http://goingon.com/sites/default/files/Drupal_Steps_4.png" alt="" width="200" height="202" /></p> <p><sup>Usability metaphors in site architecture and development practices sometimes works.</sup></p> <p>The extra work involved might well take <em>more aggregate</em> time to develop, but that time will be amortized across small, manageable pieces that can be more intelligently inserted into the development&nbsp;schedule.</p> <p>Here are the backport opportunities we’ve&nbsp;identified:</p> <h3>Design&nbsp;Patterns</h3> <p><a href="http://drupal.org/project/vertical_tabs">Vertical Tabs</a>, <a href="http://drupal.org/project/contextual">Contextual Links</a>, Toolbar, <a href="http://drupal.org/project/elements">Elements</a>, <a href="http://drupal.org/project/contact">Contact</a></p> <p>Many of the design patterns in Drupal 7 are available through a combination of backport modules and creative theming. The Toolbar module doesn’t have a backport, but peeking into the repository for the <a href="http://drupal.org/project/admin_menu">Admin Menu</a> I spy something that makes it <em>look</em> like D7’s&nbsp;Toolbar.</p> <p>By pulling these patterns from D7, we gain two&nbsp;benefits:</p> <ul> <li>We can build out the rest of our user interface around D7 design assumptions, instead of D6 assumptions. This will save effort in a theme redesign and&nbsp;upgrade.</li> </ul> <ul> <li>We can trickle D7 designs in front of our users, allowing them to adjust to a few changes ahead of time instead of waking up one morning to find a completely rearranged&nbsp;website.</li> </ul> <p><em>Our use of Vertical Tabs liberally around node forms is not cutting edge, but has allowed us to package complex forms with a Drupal 7 pattern, instead of resorting to harder-to-maintain multi-step&nbsp;forms.</em></p> <h3>System&nbsp;Plumbing*</h3> <p><a href="http://drupal.org/project/drupal_queue">Drupal Queue</a>, <a href="http://drupal.org/project/adminrole">Admin Role</a>, <a href="http://drupal.org/project/password">Password</a>, <a href="http://drupal.org/project/hook_file">File</a>, <a href="http://drupal.org/project/mailsystem">Mail System</a>, <a href="http://drupal.org/project/simpletest">Simpletest</a></p> <p>The flow of code that goes on under the hood has a few interface points where it is relatively easy to grab a D6 backport and make your modules look just a little more like Drupal 7&nbsp;code.</p> <p>Judging by an <span class="caps">IRC</span> chat I just overheard the files[] mechanism might be dropped for something simpler in one of the next few point&nbsp;releases.</p> <p><em>I hadn’t realized until writing this that <span class="caps">URL</span> Alter was cooked into core. The ability to ignore the special rules around around <a href="http://api.drupal.org/api/drupal/developer--hooks--core.php/function/custom_url_rewrite_inbound/6">custom_url_rewrite_inbound()</a>  and go straight for <a href="http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_url_inbound_alter/7">hook_url_inbound_alter()</a> is great. It also makes our custom code using it D7&nbsp;ready.</em></p> <p>* For purposes of this post, plumbing refers to the flow of code and data between its storage and the rendering process. Pretty broad&nbsp;category.</p> <h3>Database <span class="amp">&amp;</span>&nbsp;Performance</h3> <p><a href="http://pressflow.org/">Pressflow</a>, <a href="http://drupal.org/project/dbtng"><span class="caps">DBTNG</span></a>, <a href="http://drupal.org/project/cache_backport">Cache&nbsp;Backport</a></p> <p>You can get a lot closer to Drupal 7 performance behaviors simply by using Pressflow, which has held backports from and experiments for Drupal 7 for&nbsp;years.</p> <p><em>Most members of the Drupal community are already well aware that if performance is important for your project, grabbing Pressflow is an easy and non-threatening win. By using it for D6, you will be coding against session handling that is closer to D7’s, as well as being able to make use of other performance enhancing systems, such as serving images via <a href="http://drupal.org/project/varnish">Varnish</a> as an ongoing improvement across your upgrade&nbsp;process.</em></p> <h3>Contrib&nbsp;Backports</h3> <p>This is a category of another sort. Usually when you think about Contrib modules for D7, you are looking for the upgraded version of the modules you are already using. However, what if there is a D7 module you want to use, or at least, could use? The D6 version of that module has just become a backport to facilitate your upgrade&nbsp;path.</p> <p>This is a good solution to deal with unmaintained modules that have since been eclipsed by more energetic projects, as well as custom code you don’t really want to see again. We’re pretty excited to start playing with the <a href="http://drupal.org/project/boxes">Boxes </a>module for this&nbsp;reason.</p> <p>I’m going to skip listing competing modules in which one has an upgrade path and not the other. The <a href="http://groups.drupal.org/similar-module-review">Similar Module Review</a> group might have information that will help you find competing modules that may just be a cleaner path&nbsp;forward.</p> <p><em>Thanks to <a href="http://www.lullabot.com/articles/friday-roundup-drupal-8-education-agile-bacon-and-roombas">Lullabot’s Friday Roundup </a>(June 24th) for pointing out backports of Password, Contact, and File. Thanks to David Reid for creating and maintaining what seems like most of these&nbsp;modules.</em></p> <p><em><strong>So, did this work? </strong>We are still putting together the details of this plan. A followup post in a few months will report on how it goes. If you have thoughts about this approach to the upgrade, additional worthwhile backports, or alternate ideas on how to make the time for an upgrade, please post a&nbsp;comment!</em></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/drupal6">drupal6</a></div><div class="field-item even"><a href="/taxonomy/term/84">drupal7</a></div><div class="field-item odd"><a href="/taxonomy/term/85">upgrade</a></div></div></div> Wed, 17 Aug 2011 05:40:01 +0000 Grayside 92 at http://grayside.org http://grayside.org/2011/08/d7-upgrade-process-backports-close-gap#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 Node Form Dominos via Node Reference and Prepopulate http://grayside.org/2010/09/node-form-dominos-node-reference-and-prepopulate <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I like Prepopulate. I like to have that pseudo-RESTful way of preloading a form to minimize the amount of work a user has to do to get to the point of submitting a form. But I also like clean URLs. This post reviews in detail a technique to use a single prepopulated nodereference field to prepopulate a bunch of other fields based on that reference. Since <a href="http://drupal.org/project/prepopulate">Prepopulate&#8217;s</a> recent 2.0 release, it because a whole lot more difficult to use the <a href="http://drupal.org/node/37775">Form <span class="caps">API</span></a> to work magic on what it provides.</p> <p>I use this in conjunction with nodereference to tailor node forms for their relationship with the referenced node.</p> <h2>Step 1: Setting up your links</h2> <p>In order for anything to happen, first you need to shape your links properly. The way to use Prepopulate with Node Reference fields (any many others) has subtly shifted. In the case of nodereference, you now what your querystring to look like this:</p> <div class="geshifilter"> <div class="php geshifilter-php" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">edit<span style="color: #009900;">&#91;</span>field_my_nodereference_field<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>∆<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>nid<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>nid<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#91;</span>nid<span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">###]</span></pre></div> </div> <p>Where <strong>∆</strong> is the delta of your field (probably 0), and <strong>###</strong> is the Node <span class="caps">NID</span>.</p> <h2>Step 2: Set up a module</h2> <p>Create a new module, or use any old custom module you have laying around. Be sure it&#8217;s weight is higher than Prepopulate&#8217;s lofty &#8220;10&#8221;, because your module needs to react to what Prepopulate does. Read up on <a href="http://drupal.org/node/110238">setting your module&#8217;s weight</a> if need be.</p> <p>You could avoid worrying about module weight if you wanted to wrangle the <span class="caps">URL</span> on your own, but at that point why are you using Prepopulate?</p> <h2>Step 3: hook_form_alter() and #after_build</h2> <p>This post won&#8217;t review how to use hook_form_alter(), but if you do not know about this amazing function, I am shocked. <a href="http://api.drupal.org/api/function/hook_form_alter/6">Go read up on it</a>. <a href="http://api.drupal.org/api/drupal/developer&#8211;topics&#8211;forms_api_reference.html/6">Master it</a>. And return here.</p> <p><em>hook_form_alter()</em> is great to change a form before it&#8217;s built. But Prepopulate now applies it&#8217;s changes after the form is built. That means you need to use <em>#after_build</em> to specify another function to come along after Prepopulate, grab the values it has applied, and make your changes.</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: #000000; font-weight: bold;">function</span> custom_form_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$form_state</span><span style="color: #339933;">,</span> <span style="color: #000088;">$form_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #666666; font-style: italic;">// You might want to put a check somewhere that this should only apply to</span> &nbsp; <span style="color: #666666; font-style: italic;">// new users or new nodes. For example, if ($form['#node']-&gt;nid == <span class="caps">NULL</span>)</span> &nbsp; <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#after_build'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'custom_prepopulate_after_build'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <h2>Step 4: Grab the referenced node.</h2> <p>In order to inherit some values from the referenced node, you need to load it.</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: #000000; font-weight: bold;">function</span> custom_prepopulate_after_build<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$form_state</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> node_load<span style="color: #009900;">&#40;</span>custom_prepopulate_nodereference_nid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_my_nodereference_field'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Bad reference from prepopulate. Nothing more to be done.</span> &nbsp; &nbsp; <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Do stuff to your form here.</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// <span class="caps">DO</span> <span class="caps">NOT</span> <span class="caps">FORGET</span> <span class="caps">THIS</span>!</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #009933; font-style: italic;">/** &nbsp;* Get the nid from the string [nid: #] &nbsp;* &nbsp;* @param $value &nbsp;* &nbsp;String containing the nid. &nbsp;* &nbsp;* @return &nbsp;* &nbsp;Integer value of a prospective nid. &nbsp;* @see nodereference_autocomplete_validate &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_prepopulate_nodereference_nid<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_field</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^(?:\s\*|(.\*) )?\[\s\*nid\s\*:\s\*(\d+)\s\*\]$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Explicit [nid:n].</span> &nbsp; &nbsp; <a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$nid</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <h2>Step 5: Time for dominos</h2> <p>Now that we have a code skeleton with all the data we need, we can start in with some magic.</p> <p>Put things like this in the &#8220;do stuff&#8221; section commented in the code block above.</p> <h3>Title Inheritance</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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#default_value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'title'</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: #339933;">=</span> <span style="color: #0000ff;">'Discussion of &quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <h3>Taxonomy Inheritance</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: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'taxonomy'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tags'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$vid</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$taxonomy</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: #339933;">!</span><a href="http://www.php.net/is_numeric"><span style="color: #990000;">is_numeric</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'taxonomy'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tags'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$vid</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'#default_value'</span><span style="color: #009900;">&#93;</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;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'taxonomy'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tags'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$vid</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: #339933;">=</span> taxonomy_implode_tags<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">taxonomy</span><span style="color: #339933;">,</span> <span style="color: #000088;">$vid</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> <h2>Was that complex?</h2> <p>Seems a bit involved, so I&#8217;m working out the best way to produce a helper module.</p> <p>If what you want is to inherit values into your output, check out the <a href="http://drupal.org/project/field_inherit">Field Inherit</a>&nbsp;project.</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/prepopulate">prepopulate</a></div><div class="field-item odd"><a href="/category/terms/drupal6">drupal6</a></div><div class="field-item even"><a href="/category/terms/nodereference">nodereference</a></div><div class="field-item odd"><a href="/category/terms/ux">ux</a></div></div></div> Thu, 02 Sep 2010 20:47:04 +0000 Grayside 88 at http://grayside.org http://grayside.org/2010/09/node-form-dominos-node-reference-and-prepopulate#comments Kicking Off OG Privacy http://grayside.org/2010/08/kicking-og-privacy <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I&#8217;ve just published the <a href="http://drupal.org/project/og_privacy">Organic Groups Privacy</a> module to Drupal.Org. It&#8217;s an <span class="caps">API</span> module intended to help give developers an easy and flexible way to define public access to Organic Groups posts. It exists specifically so I can convince <a href="http://drupal.org/project/spaces">Spaces</a> that I really mean it when I say an arbitrary 90% of an Organic Group should be private.</p> <p>It is bundled with a Feature that demonstrates how you might integrate it with an Open Atrium site, but the core of <span class="caps">OG</span> Privacy can be useful even without Spaces being in the mix at all.</p> <p>With it, you can do such neat things as declare all Blog posts private to group members with a simple hook implementation:</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_og_privacy_policy_info(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_og_privacy_policy_info<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$policies</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$policies</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'private_blog_type'</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; <span style="color: #0000ff;">'access callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'custom_private_blog_policy'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #0000ff;">'reason'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Blog posts are only viewable by group members.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$policies</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #009933; font-style: italic;">/** &nbsp;* Blog type privacy policy callback. &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> og_privacy_blog_type_policy<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'blog'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>If you read through the <a href="http://drupalcode.org/viewvc/drupal/contributions/modules/og_privacy/og_privacy.api.php?view=markup"><span class="caps">API</span> documentation</a>, you will see that the above policy is <em>implicitly non-exclusive</em> meaning any old module could come along with it&#8217;s own policy to make a blog post visible.</p> <p>For an example of an exclusive policy, which exercises supreme executive veto power to guarantee the privacy of, say, all the content from your Atrium Casetracker feature, it might look like this:</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_og_privacy_policy_info(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_og_privacy_policy_info<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$policies</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #000088;">$policies</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'private_atrium_casetracker'</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; <span style="color: #0000ff;">'access callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'custom_private_atrium_casetracker_policy'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #0000ff;">'reason'</span> <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content types created by the casetracker feature are viewable only by group members.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #0000ff;">'exclusive'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;"><span class="caps">TRUE</span></span><span style="color: #339933;">,</span> &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$policies</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #009933; font-style: italic;">/** &nbsp;* Atrium Case Tracker privacy policy callback. &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> og_privacy_atrium_casetracker_policy<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$map</span> <span style="color: #339933;">=</span> features_get_component_map<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'node'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$map</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#93;</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;">$feature</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/reset"><span style="color: #990000;">reset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$map</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$feature</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'atrium_casetracker'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;"><span class="caps">TRUE</span></span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>By building your own selection of exportables and <em>hook_form_alter()</em> implementations around such policy definitions you can control public access very easily.</p> <p>For a somewhat more detailed explanation of the guts of how this works, <a href="http://drupalcode.org/viewvc/drupal/contributions/modules/og_privacy/<span class="caps">README</span>.txt?view=markup">check out the&nbsp;<span class="caps">README</span></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="/category/terms/modules">modules</a></div><div class="field-item odd"><a href="/category/terms/spaces">spaces</a></div><div class="field-item even"><a href="/category/terms/og">og</a></div><div class="field-item odd"><a href="/category/terms/access">access</a></div></div></div> Mon, 16 Aug 2010 20:38:15 +0000 Grayside 87 at http://grayside.org http://grayside.org/2010/08/kicking-og-privacy#comments Spaces Integrating a CCK Field http://grayside.org/2010/07/spaces-integrating-cck-field <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I wanted to make a <span class="caps">CCK</span> Field available only when a given feature was enabled. It turns out it&#8217;s really easy.</p> <p><span class="caps">CCK</span> comes with a <em>hook_field_access()</em> hook (see <a href="http://api.lullabot.com/content_access">content_access()</a>). Any implementation of this function that returns <span class="caps">FALSE</span> for a given field results in that field being denied to the user.</p> <p>By implementing this function with a <a href="http://drupal.org/project/spaces">Spaces</a> <span class="caps">API</span> call instead of the content_permissions module approach of a new, field-specific permission, all kinds of magic becomes possible.</p> <p>Read on for demonstration code.</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_field_access(). &nbsp;* Allow View/Edit access to 'field_my_cck_field' only when 'feature_name' is enabled. &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_field_access<span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$account</span><span style="color: #339933;">,</span> <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;"><span class="caps">NULL</span></span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #666666; font-style: italic;">// Be sure not to affect other fields.</span> &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_name'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'field_my_cck_field'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;"><span class="caps">TRUE</span></span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> &nbsp; &nbsp; <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$op</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'edit'</span><span style="color: #339933;">:</span> &nbsp; &nbsp; <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'view'</span><span style="color: #339933;">:</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Make access contingent on whether a given feature is enabled in the current space, such as atrium_book.</span> &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> spaces_access_feature<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'view'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'feature_name'</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><strong><span class="caps">EDIT</span>: <a href="http://drupal.org/node/887272">Issue posted</a> to the Spaces queue with patch to add this functionality generically for all&nbsp;fields.</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/cck">cck</a></div><div class="field-item odd"><a href="/category/terms/openatrium">openatrium</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/spaces">spaces</a></div></div></div> Mon, 26 Jul 2010 20:25:09 +0000 Grayside 86 at http://grayside.org http://grayside.org/2010/07/spaces-integrating-cck-field#comments Modifying Contexts the Old-Fashioned Way http://grayside.org/2010/06/modifying-contexts-old-fashioned-way <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>There are two ways to change <a href="http://drupal.org/project/context">contexts</a>. The new awesomeness is to use <a href="http://drupal.org/project/features">Features</a> or other exportable techniques to create a new version of your modified contexts, and push the old ones out of the way.</p> <p>However, when I avoid hacking [atrium] core, I prefer the old way&#8211;today that&#8217;s alter hooks.</p> <p>Alter hooks in Context allow you to do zany things like modifying the <em>conditions</em> or <em>reactions</em> associated with a given context. Naturally, if the original context slides out from under your original assumptions you&#8217;ll have to make some changes. In the meantime, just remember that using such powerful things as hook_context_load_alter() you can completely break a context if you are not careful.</p> <p>Below are some examples of context manipulations I&#8217;ve learned through a bit of code trawling and error trials.</p> <p>For the sake of (some) future compatibility I am using the Context <span class="caps">API</span> as of 3.0-beta4.</p> <p>&gt; <em><span class="caps">EDIT</span>: The method previously illustrated here for altering context conditions via hook_context_load_alter() was flat-out wrong, and will not work. Unless you were to use it to preload the context_ui just to go to the context ui edit page and click save. Then it would do something.</em></p> <h2>Adding a Content Type Condition</h2> <p>In my approach to integrating Feature Servers into OpenAtrium, I decided to pull the Project content type created by the Feature Server module into the casetracker project context. This required a new condition.</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_context_default_contexts_alter(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_context_default_contexts_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$contexts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$contexts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'spaces-feature-casetracker'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conditions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'node'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'values'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fserver_project'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'fserver_project'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <h2>Adding a Path Condition</h2> <p>In working out <span class="caps">OA</span> Book Manager, I wanted to add my new admin pages to the book context so the sidebar book navigation would stick around. Do you see where this code is broken?</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_context_default_contexts_alter(). &nbsp;\*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_context_default_contexts_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$contexts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$contexts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'spaces-feature-book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conditions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</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; <span style="color: #0000ff;">'values'</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;">'notebook/manage/\*'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'notebook/manage/*'</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>When manipulating contexts, you need to keep a close lookout for when you are adding new array elements and when you are overriding array elements. By setting the path in this way, I am clearing out any existing path-based conditions. Instead, I should assign the new path element at a deeper part of the array.</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_context_default_contexts_alter(). &nbsp;\*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_context_default_contexts_alteer<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$contexts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; <span style="color: #000088;">$contexts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'spaces-feature-book'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conditions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'values'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'notebook/manage/\*'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'notebook/manage/\*'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></div> </div> <p>This code does not blast away existing path conditions.</p> <h2>Adding a Block Reaction</h2> <p>Recently I&#8217;ve been working on creating a dashboard <span class="caps">RSS</span> feed for OpenAtrium. I wanted to add a new block to the user profile page to present some links and use instructions.</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_context_load_alter(). &nbsp;*/</span> <span style="color: #000000; font-weight: bold;">function</span> custom_context_load_alter<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$context</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;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'atrium_profile'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> &nbsp; &nbsp; <span style="color: #000088;">$block</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;">'custom-some_new_block'</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;">'module'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'custom'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'delta'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'some_new_block'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'region'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'right'</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'weight'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; &nbsp; <span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reactions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'block'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blocks'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_merge"><span style="color: #990000;">array_merge</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">reactions</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'block'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'blocks'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$block</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>This time I threw in an array_merge to avoid clobbering the existing&nbsp;blocks.</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/context">context</a></div><div class="field-item even"><a href="/category/terms/dont-hack-core">don&#039;t-hack-core</a></div></div></div> Mon, 21 Jun 2010 23:05:01 +0000 Grayside 83 at http://grayside.org http://grayside.org/2010/06/modifying-contexts-old-fashioned-way#comments Firefox's Custom Keywords and Drupal http://grayside.org/2010/06/firefoxs-custom-keywords-and-drupal <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&#8217;ve delved into some of the enhanced bookmarking magic in Firefox, you know that entering the world of the Organize Bookmarks tool provides some additional options in how you save your bookmarks.</p> <p><a href="http://www.mozilla.org/docs/end-user/keywords.html">Custom Keywords</a> are really neat. I use them for Drupal reference all the time. It&#8217;s my preferred method for bouncing around <span class="caps">CVS</span>, the <span class="caps">API</span>, and issue queues. Typing &#8220;<span class="geshifilter"><code class="text geshifilter-text">d6 hook_nodeapi</code></span>&#8221; to double check the ops is very nice. Typing &#8220;<span class="geshifilter"><code class="text geshifilter-text">dcm og</code></span>&#8221; to start researching how og access control works save a page load.</p> <p>Attached is a drupal-bookmarks.html file that will get you a leg up on the boring process of creating these bookmarks.</p> <p>It includes Drupal Project, Drupal Project Issues, Drupal Project Usage, Drupal <span class="caps">CVS</span> Modules, Drupal <span class="caps">CVS</span> Core, Drupal Site search, Drupal 6 <span class="caps">API</span> lookup, and Drupal 7 <span class="caps">API</span> lookup.</p> <p>(You can create something similar in Chrome, but it&#8217;s not done through bookmarks. Setting up <a href="http://www.makeuseof.com/tag/create-custom-search-engines-google-chrome/">Custom Search Engines</a> is very similar, and I don&#8217;t see an easy mechanism for&nbsp;exportables.)</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/firefox">firefox</a></div><div class="field-item even"><a href="/category/terms/bookmarks">bookmarks</a></div></div></div> Tue, 15 Jun 2010 21:50:10 +0000 Grayside 81 at http://grayside.org http://grayside.org/2010/06/firefoxs-custom-keywords-and-drupal#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 Drush with Bash Aliases http://grayside.org/2010/06/drush-bash-aliases <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I&#8217;ve been looking for some decent ways of managing the use of modules hosted in random Features Servers. Particularly, how do I use Drush as seamlessly with a Features Server as it works with Drupal.Org?</p> <p>It turns out that Drush has a lot of special options buried in the <em>pm-download (dl)</em> command, the very Drush maneuver most helpful for my goal. Naturally, these options can be included in a Bash Alias for Drush.</p> <div class="geshifilter"> <div class="text geshifilter-text" style="font-family:monospace;"> <pre style="font-family: monospace; font-weight: normal; font-style: normal">alias dds='drush --source=http://code.developmentseed.org/fserver dl'</pre></div> </div> <p>This alias specifically searches DevSeed&#8217;s features server for projects. Slide it into your <a href="http://www.linux.org/lessons/beginner/l6/lesson6a.html"><em>.bashrc</em> file</a>. Now a quick <em>$&gt; dds fserver</em> works like a charm.</p> <p>I still think <a href="http://grayside.org/2010/05/drush-and-features-servers">project repositories</a> like Ubuntu&#8217;s package repos (or really, Arch repositories like Core, Extra, and Aur) have a lesson for us. But that can wait on the smoothing out of functionality like <em>&#8211;destination</em>, which allows you to say where a project will be saved, but not with the same grace as Drupal.Org projects and the <em>modules/contrib/</em>&nbsp;directory.</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/drush">drush</a></div><div class="field-item odd"><a href="/category/terms/features-servers">features-servers</a></div></div></div> Thu, 10 Jun 2010 06:18:40 +0000 Grayside 80 at http://grayside.org http://grayside.org/2010/06/drush-bash-aliases#comments Integrating the Features Server into OpenAtrium http://grayside.org/2010/06/integrating-features-server-openatrium <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Working on integrating the <a href="http://code.developmentseed.org/featureserver/node/163">Features Server</a> feature into <a href="http://openatrium.com">OpenAtrium</a>. My intention is to set it up as another Casetracker Project type.</p> <p>OpenAtrium provides a solid case tracker and documentation system, and is a natural fit for the infrastructure of a Drupal.Org-style project ecosphere. Integrating them will allow me to post Features I&#8217;ve created to a place where I might actually have a means to get feedback on my work, let alone provide support.</p> <h2>Project Status of <span class="caps">OA</span> Features Server feature</h2> <ul> <li>Features Project as a Casetracker Project <strong>✓</strong></li> <li>Features Project automatically a Notebook <strong>✓</strong> </li> <li>Converting Projects View to a Site/Group feature. [in progress]</li> <li>Trivial Modification of Features Server code to play nice with OpenAtrium and Atrium Casetracker .<strong>✓</strong> [will ship with patch]</li> </ul> <h2>Conundrums</h2> <ul> <li>Features Server feature uses Context 2.0, <span class="caps">OA</span> uses Context 3.0</li> <li>hook_views_default_views_alter() has limited to no best practices or examples I&#8217;ve been able to find, given it&#8217;s currently documented intention as a site-specific hook. Somehow I don&#8217;t think it&#8217;s role will remain in site-customization in the world of&nbsp;Features.</li> </ul> </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/openatrium">openatrium</a></div><div class="field-item even"><a href="/category/terms/features-servers">features-servers</a></div></div></div> Thu, 03 Jun 2010 16:32:53 +0000 Grayside 77 at http://grayside.org http://grayside.org/2010/06/integrating-features-server-openatrium#comments cat kit | specificity http://grayside.org/2010/05/cat-kit-specificity <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 read through <a href="http://drupal.org/project/kit">Kit</a>, one of the themes that keeps cropping up is the concept of specific relevance. How do you know when it is a good idea to include a given variable, permission, or other component in your Feature?</p> <p>The answer boils down to this: <em>Keep your Feature lean and mean. Include only what&#8217;s necessary for a good, mission-complete piece of functionality.</em> The primary reason for this rule strikes me as the worthy goal of avoiding a horde of bloated, conflicting Features that will make an ill-configured wreckage of the sites that try to use them.</p> <p>Behind the fold for further thoughts about what specificity means in a well-built Feature.</p> <p>In thinking about it further (and the way I&#8217;ve used Features so far), I found a couple examples of why specificity is worth thinking about.</p> <h2>1. The Over-Configured Content Type</h2> <p>I created a Feature around a new content type. The Feature itself related to how that content was listed around the site (a couple of Views). I exported every variable related to how I had configured the content type, even though my <a href="http://drupal.org/project/vertical_tabs">Vertical Tabs</a> settings had no specific relevance to the functionality I was seeking to isolate and export.</p> <p>For an internal-use sort of Feature, I&#8217;m sure this does not matter. (Unless you are trying to define all your Vertical Tabs settings in a different Feature). For a publicly-shared feature, you have now introduced a piece of Vertical Tabs configuration which really has no bearing on the reason someone else might have been interested in your Feature.</p> <h2>2. It&#8217;s How I Use It</h2> <p>People disagree on how specialized any given modular website nugget should be. Just look at all the Drupal Modules with overly-themed defaults. Kit specificity in a Feature means the Feature includes only the aspects of theming and site integration necessary for the Feature to make sense, not that your specific use case for that Feature is realized in a shiny exported module.</p> <p>For internal-use&#8230; go for it! Kit is clearly intended as a standard for the growing world of shared Features. Exportables purely for deployment facilitation need not apply. Of course, Kit-compliance from the get-go will surely help you make the unlooked for transition to a publicly published Feature much&nbsp;easier.</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/features">features</a></div><div class="field-item even"><a href="/category/terms/kit">kit</a></div></div></div> Tue, 01 Jun 2010 06:52:43 +0000 Grayside 76 at http://grayside.org http://grayside.org/2010/05/cat-kit-specificity#comments cat kit | summarize namespacing http://grayside.org/2010/05/cat-kit-summarize-namespacing <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I decided a few notes would help me grok the <a href="http://drupal.org/project/kit">Kit Specification</a>. I post them here in case someone else finds them useful.</p> <h2>Shortest Summary</h2> <p>Project Name and Feature Name should be the same. They should have a nice, unique namespace. The human readable version doesn&#8217;t need to show the prefix. Views and other individually exported pieces should be prefixed with the not-necessarily-unique part of the Feature name.</p> <h2>Barely-Shorter Sumary</h2> <p>This summary currently covers the Features Specification 1.0-draft.</p> <h3>Code Namespace</h3> <p><strong>Covers:</strong> Filenames, function names, directory name.<br /> <strong>Rule:</strong> Make the namespace (prefix) unique.</p> <p>&gt; Domain names and Drupal.Org user names make good prefixes. Why? Because they are guaranteed unique by an external authority everyone in the Drupal community is bound to bump into.</p> <h3>Project Namespace</h3> <p><strong>Covers:</strong> Project name, as defined in .info file and a Features Server feature node.<br /> <strong>Rule:</strong> Same as the code namespace for a single-feature project.</p> <h3>Machine Name</h3> <p><strong>Covers</strong>: Generic part of the feature name.<br /> <strong>Rule:</strong> Should be short and descriptive.</p> <p>Features will generally be called <em>&lt;namespace&gt;_&lt;machine name&gt;</em>.</p> <h3>Human Readable Name</h3> <p><strong>Covers</strong>: Name of the feature, such as on the modules page. (As defined by <em>name</em> in .info file.)<br /> <strong>Rule:</strong> Skip the namespace. Stick with a descriptive name.</p> <p>(I interpret this to be a human-readable version of the Machine Name.)</p> <h3>Component Namespace</h3> <p><strong>Covers</strong>: All the bits that are exportable. (Views, Content Types, Rules, etc)<br /> <strong>Rule:</strong> Prefix with the Machine Name.</p> <h2>Example</h2> <p>Here are the namespace selections for a project enhancing the OpenAtrium Notebook.</p> <ul> <li><strong>Namespace</strong>: grayside</li> <li><strong>Project Name</strong>: grayside_oa_book_manager</li> <li><strong>Machine Name</strong>: oa_book_manager</li> <li><strong>Human Readable Name</strong>: <span class="caps">OA</span> Book Manager</li> <li><strong>Component Namespace</strong>: <ul> <li><em>View:</em> oa_book_manager_bulk_update</li> <li><em>Rule:</em>&nbsp;oa_book_manager_new_page_message</li> </ul> </li> </ul> </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/features">features</a></div><div class="field-item even"><a href="/category/terms/kit">kit</a></div><div class="field-item odd"><a href="/category/terms/namespace">namespace</a></div></div></div> Sun, 23 May 2010 06:03:15 +0000 Grayside 75 at http://grayside.org http://grayside.org/2010/05/cat-kit-summarize-namespacing#comments Freelinking 1.9 Release Sighted http://grayside.org/2010/03/freelinking-19-release-sighted <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>Freelinking 1.x was previously announced as feature-frozen, and the next thing to unsupported. Looking at the long development cycle for Freelinking 3 reaching stability, the issue queue was dusted off.</p> <p>Freelinking 1.9 will fix a number of bugs in 1.8, and smooth out the transition to <span class="caps">FL3</span>. Please go on over to the <a href="http://drupal.org/project/freelinking">Freelinking</a> homepage and download the <a href="http://drupal.org/node/180838">dev version</a> to try it out.</p> <p>Freelinking 1.9 will be released this&nbsp;week.</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/freelinking">freelinking</a></div><div class="field-item odd"><a href="/category/terms/modules">modules</a></div><div class="field-item even"><a href="/category/terms/drupal6">drupal6</a></div></div></div> Sun, 28 Mar 2010 06:31:37 +0000 Grayside 59 at http://grayside.org http://grayside.org/2010/03/freelinking-19-release-sighted#comments Overriding Prepopulate: Do Not Use hook_form_FORM_ID_alter http://grayside.org/2010/02/overriding-prepopulate-do-not-use-hookformformidalter <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>&gt; <strong><span class="caps">EDIT</span>: As of Prepopulate 2.0, you cannot directly use hook_form_alter() anyway. See <a href="http://grayside.org/2010/09/node-form-dominos-node-reference-and-prepopulate">Node Form Dominos</a> to learn about using #after_build to work with Prepopulated values. &#8211; 2010/09/09</strong></p> <p>The <a href="http://drupal.org/project/prepopulate">Prepopulate</a> module works some great magic to preload forms from <span class="caps">URL</span> variables. But suppose you need some extra magic to modify the titles it puts in place?</p> <p>You can always use <tt>hook_form_alter</tt> (and <a href="http://drupal.org/node/651106">here</a> is one of countless little tutorials on that).</p> <p>If you already know about that, you might be someone that enjoys the use of <tt>hook_form_FORM_ID_alter()</tt>. If you do, you <strong>cannot</strong> use it to override Prepopulate-set fields. It turns out that regardless of module weight, <tt>hook_form_FORM_ID_alter</tt> is called before <tt>hook_form_alter</tt> for any given form, meaning that the more specific function will always set the value, then Prepopulate will come along and reset it to your <span class="caps">URL</span> value.</p> <p>There is a nice issue (<a href="http://drupal.org/node/300481">#300481</a>) that details this problem, and hopefully will find itself fixed in Drupal&nbsp;8.</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/prepopulate">prepopulate</a></div><div class="field-item even"><a href="/category/terms/drupal6">drupal6</a></div><div class="field-item odd"><a href="/category/terms/hookformalter">hook_form_alter</a></div><div class="field-item even"><a href="/category/terms/drupal8">drupal8</a></div></div></div> Fri, 12 Feb 2010 19:31:30 +0000 Grayside 54 at http://grayside.org http://grayside.org/2010/02/overriding-prepopulate-do-not-use-hookformformidalter#comments Freelinking 3: Forging Ahead http://grayside.org/2009/11/freelinking-3-forging-ahead <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>Since I have recently become a co-maintainer on <a href="http://drupal.org/project/freelinking">Freelinking</a>, and am now leading Freelinking 3 onward to the next Alpha release, I felt a need to philosophize about Freelinking and where it is going.</em></p> <p>One of the biggest differences between traditional writing and composing for the web is the ability to easily interconnect information. Inline references for immediate &#8220;further reading&#8221; are really powerful, really easy for readers, and really annoying for writers. Be it composing <span class="caps">HTML</span> or clicking buttons, creating links interrupts the flow of ideas. Suddenly we have a trade-off between a bad writer experience and a limited reader experience.</p> <p>Enter Freelinking, the Drupal module that addresses the simple, wiki-like approach to creating links, providing the kind of shorthand notation that minimizes the impact on writers.</p> <p>Freelinking has a long history, and in the past has focused on making the titles of nodes into links to those nodes within your Drupal site. That has changed. In it&#8217;s third generation, Freelinking 3 has <a href="http://oif.eafarris.com/blog/freelinking-module-is-undergoing-a-rewrite">expanded focus</a> to become a framework for developers to quickly create an &#8220;easy-linking&#8221; syntax. While it is only in an Alpha release, and features and functionality are still transforming and growing, there is already enough to start talking about what Freelinking 3 can offer, and ask for more feedback on where it should be going.</p> <h3>So what does Freelinking 3 provide for Users creating content?</h3> <ol> <li>Quickly link to content of interest without needing to look up the details of a commonly referenced web address, or type the same most-of-a-url over and over.</li> <li>Have your internal links enriched with details held within the website&#8217;s database about the page to which you are linking.</li> <li>Create a number of different types of links by using the plugin syntax (<em>[[search:terms]]</em> for the Search plugin.)</li> </ol> <h3>So what does Freelinking 3 provide for Administrators <span class="amp">&amp;</span> Site Builders?</h3> <ol> <li>Tailor the syntax used to mark a &#8220;freelink&#8221; by selecting single brackets, double brackets, or Markdown-style links.</li> <li>Choose a plugin as &#8220;default&#8221; to minimize the syntax for the most common type of link created on your site. (Internal node titles still an option!)</li> <li>Theme different types of links without needing to parse URLs or beg for <span class="caps">CSS</span> classes in issue queues.</li> </ol> <h3>So what does Freelinking 3 provide for Themers?</h3> <ol> <li>Use the provided <em>theme</em> functions to easily change the presentation of links in your content, or even build out other <span class="caps">HTML</span> based on the values passed as pieces of a link. </li> <li>Make use of standardized <span class="caps">CSS</span> classes (to which plugins can add) for easy <span class="caps">CSS</span>-only theming of links.</li> </ol> <h3>So what does Freelinking 3 provide for Developers?</h3> <ol> <li>Easily insert a Freelinking plugin into any module to create relevant linking syntax on the spot. (<tt>hook_freelinking</tt>)</li> <li>Easily integrate your module into the linking syntax of a site by modifying the values used to build the <span class="caps">HTML</span> link. (<tt>hook_freelink_alter</tt>)</li> <li>Easily learn and create Freelinking plugins by dropping files into the Freelinking directory, skipping the need to become a module developer. (Just a .inc file!)</li> <li>Work within the clear scope of &#8220;linking&#8221; and have access to the Drupal module-scape within that focused lens. (Nodewords for better tooltips, Prepopulate for new node creation, etc)</li> <li>Make use of the Freelinking <span class="caps">API</span> to dramatically extend Freelinking, or the ways Freelinking can improve your site. (<a href="http://drupal.org/node/621180#comment-2219320">Building a Robust <span class="caps">FL3</span> <span class="caps">API</span></a>)</li> </ol> <p>Why do all this work for a linking syntax module? Freelinking works very hard to help developers achieve what is obviously and easily doable with simple regular expressions in a custom module, or a general purpose regex filtering module such as <a href="http://drupal.org/project/customfilter">Custom Filter</a>. But by building off of the specialized &#8220;linking syntax framework&#8221; here, you can get the syntax you want faster, with less module overhead, and take full advantage of the Drupal and Theme integration that Freelinking provides. The specialization on this one <span class="caps">HTML</span> element allows it to help developers more.</p> <p>In order to advance Freelinking&#8217;s mission to become the foundation of all link syntax modules in the Drupal sphere, please join me in the <a href="http://drupal.org/project/issues/freelinking">Freelinking Issue Queue</a>. Drop in on the <a href="http://drupal.org/node/613236#comment-2217816"><span class="caps">FL</span> 3 Roadmap</a> thread to discuss the high level goals <span class="caps">FL3</span> should pursue, especially while Freelinking is still undergoing dramatic transformation during Alpha. Use Cases&nbsp;wanted!</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/freelinking">freelinking</a></div><div class="field-item even"><a href="/category/terms/fl3">FL3</a></div></div></div> Sat, 21 Nov 2009 07:58:41 +0000 Grayside 47 at http://grayside.org http://grayside.org/2009/11/freelinking-3-forging-ahead#comments Prepopulating Casetracker http://grayside.org/2009/11/prepopulating-casetracker <div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>The <a href="http://drupal.org/project/prepopulate">Prepopulate</a> module for <a href="http://drupal.org">Drupal</a> is a nifty little tool that resets the default values of forms on their way to the browser. This is particularly useful for crafting links to create nodes with pre-set values. You can even prepopulate <a href="http://drupal.org/project/casetracker">Case Tracker</a> form values to help users create cases filled out as you would like.</p> <p>This mechanism is entirely dependent on the <span class="caps">URL</span> your users click. Be prepared to replace children in the Create Content <a href="http://drupal.org/getting-started/6/admin/build/menu">menu</a> or even create a custom module and <a href="http://api.drupal.org/api/function/hook_form_alter/6">hook_form_alter</a> links around your site if you want these changes to approach universal use.</p> <h2>The Basics</h2> <p>First off, know your <span class="caps">URL</span>. We will be adding a query string to the url <tt>node/add/casetracker-basic-case</tt><br /> If you want, you can imagine it starts off with <em>http://www.example.com/</em> but Drupal can take care of that.</p> <p>To set a default title, you need to add a bit of a query string: <tt>?edit[title]=New Case Title</tt>.</p> <p>Our <span class="caps">URL</span> now looks like:<br /> <code>node/add/casetracker-basic-case?edit[title]=New Case Title</code></p> <p>We can also modify the body:<br /> <code>node/add/casetracker-basic-case?edit[title]=New Case Title&amp;amp;edit[body_field][body]=This is a prepopulate-created case.</code></p> <p>Or perhaps add a few taxonomy tags (tagging vocabularies only):<br /> <code>node/add/casetracker-basic-case?edit[taxonomy][tags][]=casetracker, drupal, prepopulate</code></p> <h4>What is the <span class="caps">VID</span>?</h4> <p>The Vocabulary <span class="caps">ID</span> can be found at your admin/content/taxonomy page. Look at the number at the end of the <em>Edit Vocabulary</em> link next to each vocabulary.</p> <h2>Case Tracker Values</h2> <p>Now that we understand the basic idea of how this works, we will run through the various Case Tracker-specific fields.</p> <h3>Project</h3> <p>To specify the project your new case will be associated with, you need to know the Node <span class="caps">ID</span> of the Project. To get a quick list of all the project IDs, you can view source on the <tt>node/add/casetracker-basic-case</tt> page and the select drop-down for projects will list the nid&#8217;s in the <tt>value</tt> attribute of each option.</p> <p><code>node/add/casetracker-basic-case?edit[casetracker][pid]=2</code></p> <h3>Assigned User</h3> <p>The assigned users are specified by username. Remember, not just any user can be assigned tickets, only those that can access the case tracker.</p> <p><code>node/add/casetracker-basic-case?edit[casetracker][assign_to]=workerbee</code></p> <h3>Status, Priority, <span class="amp">&amp;</span> Type</h3> <p>The &#8220;state&#8221; information of your case is a little more difficult to determine. I suggest you return to the View Source trick from the Project section, as you need the id codes for each status, priority, and type value.</p> <p>For this example, Status &#8220;Postponed&#8221; is <tt>6</tt>, Priority &#8220;Critical&#8221; is <tt>14</tt>, and Type &#8220;General Task&#8221; is <tt>11</tt>.</p> <p><code>node/add/casetracker-basic-case?edit[casetracker][case_status_id]=6&amp;amp;edit[casetracker][case_type_id]=11&amp;amp;edit[casetracker][case_priority_id]=14</code></p> <h2>How Do I Prepopulate Other Fields?</h2> <p>If you want to learn more about the Prepopulate module, take a look at it&#8217;s <a href="http://drupal.org/node/228167">Handbook Page</a>. Even better (and more current) are the Usage Notes packaged in the module release in <a href="http://cvs.drupal.org/viewvc/drupal/contributions/modules/prepopulate/<span class="caps">USAGE</span>.txt?revision=1.5&amp;view=markup"><span class="caps">USAGE</span>.txt</a>.</p> <p>The most important thing to realize is that Prepopulate knows how to read the Forms <span class="caps">API</span> and uses that insight to replace the <tt>#default_value</tt> of each specified <span class="caps">HTML</span>&nbsp;field.</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/casetracker">casetracker</a></div><div class="field-item even"><a href="/category/terms/prepopulate">prepopulate</a></div></div></div> Tue, 03 Nov 2009 19:32:41 +0000 Grayside 43 at http://grayside.org http://grayside.org/2009/11/prepopulating-casetracker#comments