[development] Drupal 7 API Change notification: Multiple importantchanges
Daniel F. Kudwien
news at unleashedmind.com
Tue Sep 14 14:32:58 UTC 2010
Thanks, Randy!
> (issue <http://drupal.org/node/757154#comment-3408064>) More
> obscure change to Form API so hook_form_BASE_FORM_ID_alter() is
> called between hook_form_alter() and hook_form_FORM_ID_alter(),
> If you don't implement hook_forms() this probably does not affect
> you.
Note: If you are currently implementing hook_form_alter() and you check for
node_form's property $form['#node_edit_form'] to apply changes to all node
forms (of any node type) like this:
function example_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node_edit_form']) {
// Apply changes to every node form, regardless of type...
}
}
then you can simply change that code to the following now:
function example_form_node_form_alter(&$form, &$form_state, $form_id) {
// Apply changes to every node form, regardless of type...
}
In other words,
http://api.drupal.org/api/function/hook_form_BASE_FORM_ID_alter/7 is
invoked, in case Form API deals with a shared base form that has been
registered via http://api.drupal.org/api/function/hook_forms/7 -- it is not
limited to node forms or comment forms; it affects all shared form
constructors.
The patch for Drupal core in http://drupal.org/node/757154#comment-3428176
contains many examples for hook_form_alter() implementations in core
modules.
This change not only simplifies integration with shared base form
constructors, but also slightly improves performance, as the form-specific
alter hooks are only invoked when the specific form is built. Generic
hook_form_alter() implementations are invoked for all forms that are built.
However, $form['#node_edit_form'] still exists, so you can happily defer
this optimization to later.
Module upgrade guide:
http://drupal.org/update/modules/6/7#hook_form_BASE_FORMID_alter
http://drupal.org/update/modules/6/7#comment_form
http://drupal.org/update/modules/6/7#node_form
sun
More information about the development
mailing list