【问题标题】:Do not show path to sub menu items in breadcrumb不要在面包屑中显示子菜单项的路径
【发布时间】:2019-01-18 20:17:34
【问题描述】:

一旦您通过单击子菜单请求页面,我想隐藏子菜单项的路径,该路径显示在面包屑中。

这是我用来创建一个菜单项和三个子菜单项的代码:

    $items['what-to-expect'] = array(
        'title' => t('What To Expect'),
        'page callback' => 'pvmf_layout_what_to_expect',
        'access arguments' => array('access content'),
        'menu_name' => 'main-menu',
        'type' => MENU_NORMAL_ITEM,
        'weight' => 1,
        'expanded' => TRUE
      );
      $items['what-to-expect/0'] = array(
        'title' => t('Local Event'),
        'page callback' => 'pvmf_layout_what_to_expect_0',
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
        'weight' => 0
      );
      $items['what-to-expect/1'] = array(
        'title' => t('Online Event'),
        'page callback' => 'pvmf_layout_what_to_expect_1',
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
        'weight' => 1
      );
      $items['what-to-expect/2'] = array(
        'title' => t('ONE Presenters'),
        'page callback' => 'pvmf_layout_what_to_expect_2',
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
        'weight' => 2
      );

这是我看到的:

在我更改定义中的type 后,我得到的代码是:

$items['what-to-expect'] = array(
    'title' => t('What To Expect'),
    'page callback' => 'pvmf_layout_what_to_expect',
    'access arguments' => array('access content'),
    'menu_name' => 'main-menu',
    'type' => MENU_VISIBLE_IN_TREE,
    'weight' => 1,
    'expanded' => TRUE
  );
  $items['what-to-expect/0'] = array(
    'title' => t('Local Event'),
    'page callback' => 'pvmf_layout_what_to_expect_0',
    'access arguments' => array('access content'),
    'type' => MENU_VISIBLE_IN_TREE,
    'weight' => 0
  );
  $items['what-to-expect/1'] = array(
    'title' => t('Online Event'),
    'page callback' => 'pvmf_layout_what_to_expect_1',
    'access arguments' => array('access content'),
    'type' => MENU_VISIBLE_IN_TREE,
    'weight' => 1
  );
  $items['what-to-expect/2'] = array(
    'title' => t('ONE Presenters'),
    'page callback' => 'pvmf_layout_what_to_expect_2',
    'access arguments' => array('access content'),
    'type' => MENU_VISIBLE_IN_TREE,
    'weight' => 2
  );

但面包屑仍然会继续显示。我试图通过转到Configuration -> Performance 来清除缓存,但它没有帮助。我可能会错过什么?

我检查了menu.inc 实际上包含:

/**
 * Menu type -- A "normal" menu item that's shown in menu and breadcrumbs.
 *
 * Normal menu items show up in the menu tree and can be moved/hidden by
 * the administrator. Use this for most menu items. It is the default value if
 * no menu item type is specified.
 */
define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB);

【问题讨论】:

    标签: php drupal drop-down-menu drupal-7 hook-menu


    【解决方案1】:

    在子菜单项定义中使用type => MENU_VISIBLE_IN_TREE,以便它们仅在菜单中可见,而不是在面包屑中。

    菜单项类型的标志在includes/menu.inc 中定义。我们可以看到MENU_NORMAL_ITEM 标志位来自MENU_VISIBLE_IN_TREEMENU_VISIBLE_IN_BREADCRUMB 的按位或运算:

    /**
     * Menu type -- A "normal" menu item that's shown in menu and breadcrumbs.
     *
     * Normal menu items show up in the menu tree and can be moved/hidden by
     * the administrator. Use this for most menu items. It is the default value if
     * no menu item type is specified.
     */
    define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB);
    

    这意味着未在面包屑中显示的MENU_NORMAL_ITEM 的标志是MENU_VISIBLE_IN_TREE

    【讨论】:

    • 能否请您告知这里还有什么问题?谢谢。
    • 不是只能用css来做吗?例如,here。再次感谢您。
    • 如果您仍然在面包屑中看到这些项目,则可能是启用了像 easy_breadcrumb 这样的自定义面包屑模块​​,在这种情况下,您需要检查模块配置。或者可能是模板文件中的某些硬代码正在显示面包屑,无论菜单项类型如何,请检查您的模板文件。您仍然可以通过 css 隐藏它,但这取决于您的活动主题(您提供的链接指的是特定主题,@see .adminimal-theme 类,因此您需要使用正确的选择器)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多