Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. function mytheme_preprocess_block__menu_block(&$variables) {
  2. if ($variables['elements']['#id'] == 'left_navigation' && !empty($variables['elements']['content']['#items'])) {
  3. $children = $variables['elements']['content']['#items'];
  4. $top_child = key($children);
  5.  
  6. $menu_link_manager = Drupal::service('plugin.manager.menu.link');
  7. $menu_link_parents = $menu_link_manager->getParentIds($top_child);
  8.  
  9. // the one we want should be the second one. the first one is the one in the main navigation across the top.
  10. $parent = end($menu_link_parents);
  11. $parent = str_replace('menu_link_content:', '' , $parent);
  12. $menu_content = current(Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(array('uuid' => $parent)));
  13.  
  14. $variables['top_parent'] = [
  15. 'title' => $menu_content->getTitle(),
  16. 'url' => $menu_content->getUrlObject()
  17. ];
  18. }
  19. }
  20.  
  21. $link = $this->menuActiveTrail->getActiveLink();
  22.  
  23. if(!empty($link->getParent())) {
  24. $parent_link = Drupal::service('plugin.manager.menu.link')->createInstance($link->getParent());
  25. $menu_item = MenuLinkContent::load($parent_link->getMetaData()['entity_id']);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement