class MenuLinkTree in Colossal Menu 8
Same name and namespace in other branches
- 2.x src/Menu/MenuLinkTree.php \Drupal\colossal_menu\Menu\MenuLinkTree
Implements the loading, transforming and rendering of menu link trees.
Hierarchy
- class \Drupal\Core\Menu\MenuLinkTree implements MenuLinkTreeInterface
- class \Drupal\colossal_menu\Menu\MenuLinkTree
Expanded class hierarchy of MenuLinkTree
1 string reference to 'MenuLinkTree'
1 service uses MenuLinkTree
File
- src/
Menu/ MenuLinkTree.php, line 18
Namespace
Drupal\colossal_menu\MenuView source
class MenuLinkTree extends CoreMenuLinkTree {
/**
* Entity Type Manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a \Drupal\Core\Menu\MenuLinkTree object.
*
* @param \Drupal\Core\Menu\MenuTreeStorageInterface $tree_storage
* The menu link tree storage.
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider to load routes by name.
* @param \Drupal\Core\Menu\MenuActiveTrailInterface $menu_active_trail
* The active menu trail service.
* @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
* The controller resolver.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The EntityTypeManager service.
*/
public function __construct(MenuTreeStorageInterface $tree_storage, RouteProviderInterface $route_provider, MenuActiveTrailInterface $menu_active_trail, ControllerResolverInterface $controller_resolver, EntityTypeManagerInterface $entity_type_manager) {
$this->treeStorage = $tree_storage;
$this->routeProvider = $route_provider;
$this->menuActiveTrail = $menu_active_trail;
$this->controllerResolver = $controller_resolver;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
protected function createInstances(array $data_tree) {
$tree = [];
foreach ($data_tree as $key => $element) {
$subtree = $this
->createInstances($element['subtree']);
// Build a MenuLinkTreeElement out of the menu tree link definition:
// transform the tree link definition into a link definition and store
// tree metadata.
$tree[$key] = new MenuLinkTreeElement($element['link'], (bool) $element['has_children'], (int) $element['depth'], (bool) $element['in_active_trail'], $subtree);
if ($tree[$key]->link instanceof AccessibleInterface) {
$tree[$key]->access = $tree[$key]->link
->access('view', NULL, TRUE);
}
}
return $tree;
}
/**
* {@inheritdoc}
*/
public function build(array $tree) {
$build = parent::build($tree);
// Use a custom theme.
if (isset($build['#theme'])) {
$build['#theme'] = 'colossal_menu__' . strtr($build['#menu_name'], '-', '_');
}
if (!empty($build['#items'])) {
$this
->addItemContent($build['#items']);
}
return $build;
}
/**
* Add the Link Content and add a no link variable.
*
* @param array $tree
* Tree of links.
*/
protected function addItemContent(array &$tree) {
foreach ($tree as &$item) {
$link = $item['original_link'];
$item['show_title'] = $link
->showTitle();
$item['identifier'] = Html::cleanCssIdentifier($link
->getMachineName());
$item['has_link'] = TRUE;
if (!$link
->isExternal() && $link
->getRouteName() == '<none>') {
$item['has_link'] = FALSE;
}
$item['content'] = $this->entityTypeManager
->getViewBuilder($link
->getEntityTypeId())
->view($link, 'default');
if (!empty($item['below'])) {
$this
->addItemContent($item['below']);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuLinkTree:: |
protected | property | The controller resolver. | |
MenuLinkTree:: |
protected | property | Entity Type Manager. | |
MenuLinkTree:: |
protected | property | The active menu trail service. | |
MenuLinkTree:: |
protected | property | The menu link plugin manager. | |
MenuLinkTree:: |
protected | property | The route provider to load routes by name. | |
MenuLinkTree:: |
protected | property | The menu link tree storage. | |
MenuLinkTree:: |
protected | function | Add the Link Content and add a no link variable. | |
MenuLinkTree:: |
public | function |
Builds a renderable array from a menu tree. Overrides MenuLinkTree:: |
|
MenuLinkTree:: |
protected | function | Builds the #items property for a menu tree's renderable array. | |
MenuLinkTree:: |
protected | function |
Returns a tree containing of MenuLinkTreeElement based upon tree data. Overrides MenuLinkTree:: |
|
MenuLinkTree:: |
public | function |
Gets the link tree parameters for rendering a specific menu. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Finds expanded links in a menu given a set of possible parents. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Finds the height of a subtree rooted by of the given ID. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Loads a menu tree with a menu link plugin instance at each element. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Returns the maximum depth of tree that is supported. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Applies menu link tree manipulators to transform the given tree. Overrides MenuLinkTreeInterface:: |
|
MenuLinkTree:: |
public | function |
Constructs a \Drupal\Core\Menu\MenuLinkTree object. Overrides MenuLinkTree:: |