如何更改Drupal中的MENU_LOCAL_TASK选项卡菜单

时间:2009-12-01 14:49:33

标签: drupal drupal-6

我在自定义Drupal 6模块中构建了一个标签式菜单。我想在我的模块页面顶部的选项卡式菜单右侧放置一个html下拉列表。该列表将在更改时触发一些ajax事件,例如通过指定10,20,50,100个结果来更改SQL查询的LIMIT子句。如何在没有黑客模板的情况下在Drupal中实现这一点?

谢谢,

2 个答案:

答案 0 :(得分:6)

您可以通过覆盖主题中的theme_menu_local_tasks()来完成此操作:

function yourTheme_menu_local_tasks() {
  // Prepare empty dropdown to allow for unconditional addition to output below
  $dropdown = '';
  // Check if the dropdown should be added to this menu
  $inject_dropdown = TRUE; // TODO: Add checking logic according to your needs, e.g. by inspecting the path via arg()
  // Injection wanted?
  if ($inject_dropdown) {
    // Yes, build the dropdown using Forms API
    $select = array(
      '#type' => 'select',
      '#title' => t('Number of results:'),
      '#options' => array('10', '20', '50', '100'),
    );
    // Wrap rendered select in <li> tag to fit within the rest of the tabs list
    $dropdown = '<li>' . drupal_render($select) . '</li>';
  }

  // NOTE: The following is just a copy of the default theme_menu_local_tasks(),
  // with the addition of the (possibly empty) $dropdown variable output
  $output = '';
  if ($primary = menu_primary_local_tasks()) {
    $output .= "<ul class=\"tabs primary\">\n". $primary . $dropdown . "</ul>\n";
  }
  if ($secondary = menu_secondary_local_tasks()) {
    $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n";
  }

  return $output;
}

(注意:未经测试的代码 - 潜在的错别字)

答案 1 :(得分:0)

当您指的是放入模块的代码时,模块应该实现hook_theme_registry_alter(),这将允许模块覆盖函数theme_menu_local_tasks()。模块应该存储前一个回调的值,这样如果页面不是应该更改的页面,它仍然可以调用它。
一旦模块被禁用,在模块中实现一个钩子允许您拥有正常的菜单选项卡;更改当前主题将要求您在需要该功能时将其更改回来,如果您使用的是其他人制作的主题,则应在下载新版本时更改主题。如果您使用多个主题,则应对每个使用过的主题进行更改 通常,应该在模块内部对模块所需的主题进行修改。