I'm upgrading from Drupal 6 to Drupal 7. I enabled this module after updating it.

Here's my function:

function sport_utils_form_alter($form, $form_state, $form_id) {
    if (strpos($form_id, '_node_form') !== FALSE) {
        $form['#validate'][] = 'byu_sport_utils_verify_valid_author';
        $form['#validate'][] = 'byu_sport_utils_remove_first_line_break';

        $form['top_buttons'] = $form['buttons'];
        $form['top_buttons']['#weight'] = -500;
        $form['top_buttons']['#prefix'] = $form['buttons']['#prefix'] = '<div class="button-bar">';
        $form['top_buttons']['#suffix'] = $form['buttons']['#suffix'] = '</div><div class="clear"></div>';
    }
}

It's throwing an error on this line:

$form['top_buttons'] = $form['buttons'];

I can't find out if I need to replace $form['buttons'] with something else that works in Drupal 7.

Any suggestions?

1

There are 1 answers

2
D34dman On

In Drupal 7 the form buttons are grouped under $form['actions']. So you need to modify your code to support that like below.

function sport_utils_form_alter($form, $form_state, $form_id) {
    if (strpos($form_id, '_node_form') !== FALSE) {
      $form['#validate'][] = 'byu_sport_utils_verify_valid_author';
      $form['#validate'][] = 'byu_sport_utils_remove_first_line_break';

      /**
        * Copy the action buttons (submit, preview, etc ..)
        * and place them at the top of the form
        */
      if(!empty($form['actions'])) {
        $actions = element_children($form['actions'], TRUE);
        foreach($actions as $name) {
          $form['top_buttons']["$name-top"] = $form['actions'][$name];
        }
      }

      $form['top_buttons']['#weight'] = -500;
      $form['top_buttons']['#prefix'] = $form['actions']['#prefix'] = '<div class="button-bar">';
      $form['top_buttons']['#suffix'] = $form['actions']['#suffix'] = '</div><div class="clear"></div>';
    }
}