Index: includes/form.inc =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/includes/form.inc,v retrieving revision 1.442 diff -u -p -r1.442 form.inc --- includes/form.inc 13 Mar 2010 22:33:05 -0000 1.442 +++ includes/form.inc 25 Mar 2010 15:09:30 -0000 @@ -746,13 +746,20 @@ function drupal_prepare_form($form_id, & } } - // Invoke hook_form_FORM_ID_alter() implementations. + // Invoke hook_form_FORM_ID_alter() implementations. We do these first so + // that the generic alter implementations can override things across all + // specific alterations if they need to. drupal_alter('form_' . $form_id, $form, $form_state); - // Invoke hook_form_alter() implementations. + // Invoke generic hook_form_alter() implementations. drupal_alter('form', $form, $form_state, $form_id); -} + // Invoke hook_form_FORM_ID_post_alter() implementations. We need to invoke + // these alter functions after the generic ones so that if someone needs + // to alter a specific form, they can alter everything about that form, even + // elements (like taxonomy) that are added by the generic form_alter() hooks. + drupal_alter('form_' . $form_id . '_post', $form, $form_state); +} /** * Validates user-submitted form data from the $form_state using Index: modules/system/system.api.php =================================================================== RCS file: /Users/wright/drupal/local_repo/drupal/modules/system/system.api.php,v retrieving revision 1.145 diff -u -p -r1.145 system.api.php --- modules/system/system.api.php 25 Mar 2010 12:19:34 -0000 1.145 +++ modules/system/system.api.php 25 Mar 2010 15:10:53 -0000 @@ -741,7 +741,9 @@ function hook_page_alter(&$page) { * altering a node form, the node object retrieved at from $form['#node']. * * Note that instead of hook_form_alter(), which is called for all forms, you - * can also use hook_form_FORM_ID_alter() to alter a specific form. + * can also use hook_form_FORM_ID_alter() to alter a specific form, or + * hook_form_FORM_ID_post_alter() to alter a specific form after all the + * generic and specific modifications have been made. * * @param $form * Nested array of form elements that comprise the form. @@ -770,8 +772,8 @@ function hook_form_alter(&$form, &$form_ * using long switch statements to alter multiple forms. * * Note that this hook fires before hook_form_alter(). Therefore all - * implementations of hook_form_FORM_ID_alter() will run before all implementations - * of hook_form_alter(), regardless of the module order. + * implementations of hook_form_FORM_ID_alter() will run before all + * implementations of hook_form_alter(), regardless of the module order. * * @param $form * Nested array of form elements that comprise the form. @@ -794,6 +796,39 @@ function hook_form_FORM_ID_alter(&$form, } /** + * Provide a form-specific alteration after the global hook_form_alter(). + * + * Modules can implement hook_form_FORM_ID_post_alter() to modify a specific + * form, rather than implementing hook_form_alter() and checking the form ID, + * or using long switch statements to alter multiple forms. + * + * Note that this hook fires after hook_form_FORM_ID_alter() and + * hook_form_alter(). Therefore all implementations of + * hook_form_FORM_ID_post_alter() will run after all implementations of + * hook_form_FORM_ID_alter() and hook_form_alter(), regardless of the module + * order. This allows final alterations to modify the entire altered form + * structure once all other modules have had their chance to change the form. + * + * @param $form + * Nested array of form elements that comprise the form. + * @param $form_state + * A keyed array containing the current state of the form. + * + * @see hook_form_alter(). + * @see drupal_prepare_form(). + */ +function hook_form_FORM_ID_post_alter(&$form, &$form_state) { + // Modification for the form with the given form ID goes here. For example, + // if FORM_ID is "user_register_form" this code would run only on the user + // registration form. + + // Completely hide all the taxonomy elements for a specific vocabulary on + // one form. + $vid = get_the_special_vocabulary_id_to_hide(); + unset($form['taxonomy'][$vid]); +} + +/** * Map form_ids to form builder functions. * * By default, when drupal_get_form() is called, the system will look for a