覆盖节点已创建/更新drupal设置消息

时间:2013-09-20 07:27:47

标签: drupal

drupal 7工作正常。

/**

 * Implementation of hook_form_alter().

 */

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {

    case 'form_id':
      $form['actions']['submit']['#submit'][] = 'MY_MODULE_custom_submit';
    break;
  }

}

function MY_MODULE_custom_submit($form, &$form_state)

{

  //Get current messages and clear them.

  $messages = drupal_get_messages('status');

  drupal_set_message(t('Your custom status message here!'));

}

1 个答案:

答案 0 :(得分:3)

只需要在那里获得正确的form_id。因此,如果节点类型为article,请使用article_node_form

此外,请不要忘记清除admin/config/development/performance处的缓存,以便系统看到更改。

/**
 * Implementation of hook_form_alter().
 */

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    // Replace NODETYPE with the machine-readable name of the node type.
    case 'NODETYPE_node_form':
      $form['actions']['submit']['#submit'][] = 'MY_MODULE_custom_submit';
    break;
  }
}

function MY_MODULE_custom_submit($form, &$form_state) {
  //Get current messages and clear them.
  $messages = drupal_get_messages('status');
  drupal_set_message(t('Your custom status message here!'));
}

希望有帮助......:)