Grayside.Org - hook_form_alter http://grayside.org/category/terms/hookformalter en 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