Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mytheme_preprocess_block__menu_block(&$variables) {
- if ($variables['elements']['#id'] == 'left_navigation' && !empty($variables['elements']['content']['#items'])) {
- $children = $variables['elements']['content']['#items'];
- $top_child = key($children);
- $menu_link_manager = Drupal::service('plugin.manager.menu.link');
- $menu_link_parents = $menu_link_manager->getParentIds($top_child);
- // the one we want should be the second one. the first one is the one in the main navigation across the top.
- $parent = end($menu_link_parents);
- $parent = str_replace('menu_link_content:', '' , $parent);
- $menu_content = current(Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(array('uuid' => $parent)));
- $variables['top_parent'] = [
- 'title' => $menu_content->getTitle(),
- 'url' => $menu_content->getUrlObject()
- ];
- }
- }
- $link = $this->menuActiveTrail->getActiveLink();
- if(!empty($link->getParent())) {
- $parent_link = Drupal::service('plugin.manager.menu.link')->createInstance($link->getParent());
- $menu_item = MenuLinkContent::load($parent_link->getMetaData()['entity_id']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement