I am working on creating a module. I have given the module a weight of 1000. When I put the code below in hook_form_alter the menu, comment settings and attachment sections of a node creation form do not show up. When I place the code in hook_form_FORM_ID_alter (having removed hook_form_alter) the menu, comment settings and attachment sections on the node creation form show up. I used the Trace module for tracing but there didn't seem to be an option for hook_form_FORM_ID_alter. From this behavior I can only reach the conclusion that hook_form_alter's are called after hook_form_FORM_ID_alter's. It should be the opposite.

function author_form_author_node_form_alter(&$form, &$form_state) {
    $form['author']=NULL;
    $form['taxonomy']=NULL;
    $form['options']=NULL;
    $form['menu']=NULL;
    $form['comment_settings']=NULL;
    $form['files']=NULL;
    $form['revision_information']=NULL;
    $form['attachments']=NULL;
    if($form["HIDEPREVIEW"]) {
      $form['buttons']['preview']=NULL;
      $form['buttons']['delete']=NULL;
    }
   // print_r($form);
   // exit();
}

function author_form_alter(&$form, &$form_state, $form_id) {
    if($form_id='author_node_form') {
        $form['author']=NULL;
        $form['taxonomy']=NULL;
        $form['options']=NULL;
        $form['menu']=NULL;
        $form['comment_settings']=NULL;
        $form['files']=NULL;
        $form['revision_information']=NULL;
        $form['attachments']=NULL;
        if($form["HIDEPREVIEW"]) {
          $form['buttons']['preview']=NULL;
          $form['buttons']['delete']=NULL;
        }
    }
   // print_r($form);
   // exit();
}

Comments

chrislynch42’s picture

Status: Active » Closed (fixed)
cweagans’s picture

Status: Closed (fixed) » Active

I can't speak to the design decisions in Form API, but I do know that you should not be setting form elements to null. Use http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.... instead.

damien tournoud’s picture

Category: bug » support
Status: Active » Fixed

Status: Fixed » Closed (fixed)
Issue tags: -hook precedence

Automatically closed -- issue fixed for 2 weeks with no activity.