0

我正在从升级Drupal 6Drupal 7. 我在更新后启用了这个模块。

这是我的功能:

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>';
    }
}

它在这一行抛出一个错误:

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

我不知道是否需要$form['buttons']用 Drupal 7 中的其他东西替换。

有什么建议么?

4

1 回答 1

0

在 Drupal 7 中,表单按钮被分组在$form['actions']. 因此,您需要修改代码以支持如下所示。

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>';
    }
}
于 2014-08-09T00:29:03.620 回答