简体   繁体   English

如何在儿童页面显示菜单所有儿童页面drupal

[英]How to show menu in children page`s all children pages drupal

This is a my code. 这是我的代码。 I show menu in page and children pages. 我在页面和子页面中显示菜单。 The question is, how to show this menu in children's all children pages? 问题是,如何在儿童的所有儿童页面中显示此菜单?

/**
* Implements hook_preprocess_page().
*/
function agnian_material_admin_preprocess_page(&$variables) {
// @todo: add an if statement to add below data only for "page__admin__content" page.
$variables['node_types'] = node_type_get_names();

/** * Render "admin/structure" page's menu in it's all subpages. / ** *在其所有子页面中呈现“admin / structure”页面的菜单。 */ * /

// get current page path
$path = \Drupal::request()->getPathInfo();
if(strpos($path, '/admin/structure') !== false) {
$tree = \Drupal::menuTree();
$params = $tree->getCurrentRouteMenuTreeParameters('admin');
$admin_menu = $tree->load('admin', $params);
$admin_structure_menu = array_key_exists('system.admin_structure', $admin_menu['system.admin']->subtree) ? $admin_menu['system.admin']->subtree['system.admin_structure'] : null;
if($admin_structure_menu) {
$subtree = $tree->build($admin_structure_menu->subtree);

/* this part is only for syncing menu items positions between "admin/structure" page and it's child pages */ / *此部分仅用于同步“admin / structure”页面与其子页面之间的菜单项位置* /

$old_items = $subtree['#items'];
$tmp = $subtree['#items'] = array();
foreach($old_items as $key => $value) $tmp[$key] = $value['title'];
asort($tmp);
foreach($tmp as $key => $value) $subtree['#items'][$key] = $old_items[$key];

/* end of sync */ / *同步结束* /

$variables['admin_menu'] = $subtree;
}
}

/** End Of Render "admin/structure" page's menu in it's all subpages. / ** End Of Render“admin / structure”页面的菜单在它的所有子页面中。 */ } * /}

try replacing 尝试更换

 if(strpos($path, '/admin/structure') !== false) {

with

 if(preg_match("/admin/structure/[^/]+/[^/]+", $path)!== false) {

[^/]+ meaning "One or more characters except slashes". [^ /] +表示“除斜线外的一个或多个字符”。

or whatever after structure should be 或结构应该是什么

     if(  preg_match("/admin/structure(.*)", $path)!== false) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM