在Drupal中覆盖Tracker模块页面的页面标题

时间:2018-03-29 09:50:02

标签: drupal drupal-7

我阅读了一些关于hook_form_alter()的帖子,但无法完成这项工作。

我想创建一个自定义模块来覆盖菜单$items' title'用于Drupal核心跟踪器模块。

function tracker_menu() {
  // ....
  $items['user/%user/track'] = array(
    'title' => 'Track',
    'page callback' => 'tracker_page',
    'page arguments' => array(1, TRUE),
    'access callback' => '_tracker_user_access',
    'access arguments' => array(1),
    'type' => MENU_LOCAL_TASK,
    'file' => 'tracker.pages.inc',
  );
  // ...
}

我试过

function mymodule_tracker_menu_form_alter(&$form, &$form_state, $form_id) {
  $items['user/%user/track']['title'] = 'Recent Content';
}

1 个答案:

答案 0 :(得分:1)

你使用了错误的钩子。您必须使用hook_menu_alterhook_form_alter()适用于表单。

/**
 * Implements hook_menu_alter().
 */
function MYMODULE_menu_alter(&$items) {

  $items['user/%user/track']['title callback'] = '_MYCALLBACK';
}

/**
 * Custom title callback.
 */
function _MYCALLBACK() {

  return t('Recent Content');
}

您还可以使用主题template.php中的预处理功能(实际上要好得多,请参阅template_process_page):

/**
 * Implements template_process_page().
 */
function MYTEMPLATE_process_page(&$variables) {

  if (arg(0) === 'user' && arg(2) === 'track) {

    $variables['title'] = t('Recent Content');
  }
}
相关问题