我甚至不知道如何问这个问题。在下面的代码(我从一个例子中找到的)中,除了默认的操纵器之外,我还想添加另一个操纵器来移除所有外部兄弟的链接。
$manipulators = array(
array('callable' => 'menu.default_tree_manipulators:checkAccess'),
array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'),
// This is what i want to do. Remove all links outside of siblings and active trail
array('callable' => 'mytheme.menu_transformers:removeInactiveTrail'),
);
将这个“removeInactiveTrail”方法放在哪个类中?
发布于 2017-12-22 18:34:51
如果你是drupal新手,问一个正确的问题总是很困难的。但是,如果您已经做到了这一点,并且找到了服务于您的任务的代码片段,那么最好研究一下核心模块和contrib模块,以了解其他人是如何使用这些函数和方法的。
如果您不确定实现,只需添加更多有关您要实现的内容的详细信息。
下面是您可以在自定义模块中使用的示例:
function mymodule_render_menu($menu_name) {
$menu_tree = \Drupal::menuTree();
// Build the typical default set of menu tree parameters.
$parameters = $menu_tree->getCurrentRouteMenuTreeParameters($menu_name);
// Load the tree based on this set of parameters.
$tree = $menu_tree->load($menu_name, $parameters);
// Transform the tree using the manipulators you want.
$manipulators = [
// Add your manipulators here
];
$tree = $menu_tree->transform($tree, $manipulators);
// Finally, build a renderable array from the transformed tree.
$menu = $menu_tree->build($tree);
return array('#markup' => render($menu));
}
上面的函数返回可渲染数组。您可以从hook_preprocess_HOOK调用,添加到变量数组中,并在模板中输出。
同样,您的任务不明确,请编辑您的问题以使其更具体。
https://stackoverflow.com/questions/47878647
复制相似问题