Hook Form Alter Help

arcane - November 21, 2008 - 22:22

I ran into a situation I cannot explain while attempting to use the two forms of hook form alter. When I print the value of $form being passed into the function using both methods, I get different results.

THe code below will print the $form array with the cck field definitions

function custom_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'press_event_node_form' && $form_state['submitted'] == FALSE) {
     var_dump($form);
  }

}

The code below does not print the cck field definitions..

function custom_form_press_event_node_form_alter(&$form, &$form_state) {
  if ($form_state['submitted'] == FALSE) {
        var_dump($form);
  }  

Given that the 2nd example is the direct form of hook form alter, wouldn't one expect the output of the $form array to be the same? Can anyone make any suggestions on why this may be?

Just a wild guess (I don't know much about CCK)

styro - November 22, 2008 - 01:34

My guess is that core invokes *_form_alter() at a later stage than it invokes *_formname_form_alter().

CCK probably has its own bunch of *_formname_form_alter() hooks that run during the same stage as your module, and that your module ends up running them before CCK does.

What happens if you change the weight of your module so that it runs those hooks after CCK runs its own?

--
Anton

 
 

Drupal is a registered trademark of Dries Buytaert.