簡體   English   中英

從drupal 6遷移到drupal 7 form_alter掛鈎會引發錯誤-注意:未定義索引:sport_utils_form_alter()中的按鈕

[英]migrating from drupal 6 to drupal 7 form_alter hook is throwing an error - Notice: Undefined index: buttons in sport_utils_form_alter()

我正在從Drupal 6升級到Drupal 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'];

我不知道是否需要用在Drupal 7中可用的其他東西替換$form['buttons']

有什么建議么?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM