当多个项目指向同一节点时,节点菜单链接与活动路径不一致

时间:2018-11-05 19:20:19

标签: drupal-modules

  

当同一节点应用于多个菜单项时, inActiveTrail 为   对于第一个菜单而不是当前菜单,请单击它。

出于测试目的,在drupal 8站点中创建多级菜单并应用以下代码,它将输出当前的活动菜单数组。只需省略$currentlinkId$parameters->setRoot即可看到数组中的inActiveTrail

$menu_tree = \Drupal::menuTree();
$menu_name = 'main';

$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
$currentLinkId = reset($parameters->activeTrail);
$parameters->setRoot($currentLinkId);
$tree = $menu_tree->load($menu_name, $parameters);

// Transform the tree using the manipulators you want.
$manipulators = array(
    // Only show links that are accessible for the current user.
    array('callable' => 'menu.default_tree_manipulators:checkAccess'),
    // Use the default sorting of menu links.
    array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
);
$tree = $menu_tree->transform($tree, $manipulators);
kint($tree);

1 个答案:

答案 0 :(得分:0)

我从以下链接获得了drupal论坛的反馈。 Drupal.org forum link