1

ノードのフォームでのみキャンセル ボタンを出力する if ステートメントを作成するのに助けが必要です。if ステートメントがないと、サイト検索フォームを含むすべてのフォームにキャンセル ボタンが表示されます。「$form_id !=」を使用してみましたが、キャンセル ボタンを配置したくない場所にすべてのフォーム ID を追加するのはあまり直感的ではないようです。どんな助けでも大歓迎です。

<?php

/**
* Implements hook_form_alter().
*/
function cancel_button_form_alter(&$form, &$form_state, $form_id) {
  // Here is where I'm having trouble. What variable can 
  // I put that targets ANY content type?
  if ($form_id != 'search_block_form') {
    // Add a cancel button.
    $form['actions']['cancel'] = array(
      '#type' => 'submit',
      '#value' => t('Cancel'),
      '#access' => TRUE,
      '#weight' => 15,
      '#submit' => array('cancel_button_form_cancel', 'node_form_submit_build_node'),
      '#limit_validation_errors' => array(),
    );
  }
}

/**
* Custom cancel button callback.
*/
function cancel_button_form_cancel($form, &$form_state) {
$url = $_GET['destination'] ? $_GET['destination'] : '';
drupal_goto($url);
}
4

1 に答える 1

1

ノード/コンテンツにいる場合、$form変数にはノード オブジェクトがあります。ただし、フォームがノード用/ノードからでない場合、ノード オブジェクトはありません。次のように確認できます。

if(isset($form['#node'])) {
    // Your code goes here
}

$form['#node']実は、私は(:P)について少し混乱しています。$formor$form_state変数をデバッグすることで取得できます。

于 2013-06-24T08:34:25.793 に答える