DefaultMenuLinkTreeManipulators
class DefaultMenuLinkTreeManipulators (View source)
Provides a couple of menu link tree manipulators.
This class provides menu link tree manipulators to:
- perform render cached menu-optimized access checking
- optimized node access checking
- generate a unique index for the elements in a tree and sorting by it
- flatten a tree (i.e. a 1-dimensional tree)
Properties
| protected AccessManagerInterface | $accessManager | The access manager. |
|
| protected AccountInterface | $account | The current user. |
|
| protected EntityTypeManagerInterface | $entityTypeManager | The entity type manager. |
Methods
Constructs a \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators object.
Performs access checks of a menu tree.
Performs access checking for nodes in an optimized way.
Collects the node links in the menu tree.
Generates a unique index and sorts by it.
Flattens the tree to a single level.
Details
__construct(AccessManagerInterface $access_manager, AccountInterface $account, EntityTypeManagerInterface $entity_type_manager)
Constructs a \Drupal\Core\Menu\DefaultMenuLinkTreeManipulators object.
MenuLinkTreeElement[]
checkAccess(array $tree)
Performs access checks of a menu tree.
Sets the 'access' property to AccessResultInterface objects on menu link tree elements. Descends into subtrees if the root of the subtree is accessible. Inaccessible subtrees are deleted, except the top-level inaccessible link, to be compatible with render caching.
(This means that top-level inaccessible links are not removed; it is up to the code doing something with the tree to exclude inaccessible links, just like MenuLinkTree::build() does. This allows those things to specify the necessary cacheability metadata.)
This is compatible with render caching, because of cache context bubbling: conditionally defined cache contexts (i.e. subtrees that are only accessible to some users) will bubble just like they do for render arrays. This is why inaccessible subtrees are deleted, except at the top-level inaccessible link: if we didn't keep the first (depth-wise) inaccessible link, we wouldn't be able to know which cache contexts would cause those subtrees to become accessible again, thus forcing us to conclude that the subtree is unconditionally inaccessible.
MenuLinkTreeElement[]
checkNodeAccess(array $tree)
Performs access checking for nodes in an optimized way.
This manipulator should be added before the generic ::checkAccess() one, because it provides a performance optimization for ::checkAccess().
protected
collectNodeLinks(array $tree, array $node_links)
Collects the node links in the menu tree.
protected AccessResultInterface
menuLinkCheckAccess(MenuLinkInterface $instance)
Checks access for one menu link instance.
MenuLinkTreeElement[]
generateIndexAndSort(array $tree)
Generates a unique index and sorts by it.
MenuLinkTreeElement[]
flatten(array $tree)
Flattens the tree to a single level.