我需要帮助创建一个 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);
}