ノードのフォームでのみキャンセル ボタンを出力する 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);
}