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

标签 drupal drupal-6

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

谢谢,

最佳答案

您可以通过覆盖 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;
}

(注意:未经测试的代码 - 潜在的拼写错误)

关于drupal - 如何更改 Drupal 中的 MENU_LOCAL_TASK 选项卡菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1826668/

相关文章:

css - 在 chrome 中显示但在 firefox 中不显示的 View 图像

.htaccess - 可以在未找到的消息中插入文本

php - 密码迁移 - Drupal SHA2 到 PHP MD5 版本

drupal - 更改 block 内容

php - 使用 PHP 在 drupal 模块中创建标准页面和表格

php - 将表格暴露给 View

php - 在 drupal_goto 之前使用 drupal_add_js

Drupal 7 浏览器特定的 css

database - drupal node_revision 中的 vid 是什么

Drupal 返回 View 中的结果数