Drupal 8  8.0.2
DefaultMenuLinkTreeManipulators Class Reference

Public Member Functions

 __construct (AccessManagerInterface $access_manager, AccountInterface $account, QueryFactory $query_factory)
 
 checkAccess (array $tree)
 
 checkNodeAccess (array $tree)
 
 generateIndexAndSort (array $tree)
 
 flatten (array $tree)
 

Protected Member Functions

 collectNodeLinks (array &$tree, array &$node_links)
 
 menuLinkCheckAccess (MenuLinkInterface $instance)
 

Protected Attributes

 $accessManager
 
 $account
 
 $queryFactory
 

Detailed Description

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)

Constructor & Destructor Documentation

__construct ( AccessManagerInterface  $access_manager,
AccountInterface  $account,
QueryFactory  $query_factory 
)

Constructs a object.

Parameters
\Drupal\Core\Access\AccessManagerInterface$access_managerThe access manager.
\Drupal\Core\Session\AccountInterface$accountThe current user.
\Drupal\Core\Entity\Query\QueryFactory$query_factoryThe entity query factory.

References Drupal\accessManager().

Here is the call graph for this function:

Member Function Documentation

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 that subtree is unconditionally inaccessible.

Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[]$tree The menu link tree to manipulate.
Returns
[] The manipulated menu link tree.

References DefaultMenuLinkTreeManipulators\menuLinkCheckAccess().

Here is the call graph for this function:

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().

Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[]$tree The menu link tree to manipulate.
Returns
[] The manipulated menu link tree.

References AccessResult\allowed(), and DefaultMenuLinkTreeManipulators\collectNodeLinks().

Here is the call graph for this function:

collectNodeLinks ( array &  $tree,
array &  $node_links 
)
protected

Collects the node links in the menu tree.

Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[]$tree The menu link tree to manipulate.
array$node_linksStores references to menu link elements to effectively set access.
Returns
[] The manipulated menu link tree.

References AccessResult\neutral().

Referenced by DefaultMenuLinkTreeManipulators\checkNodeAccess().

Here is the call graph for this function:

Here is the caller graph for this function:

flatten ( array  $tree)

Flattens the tree to a single level.

Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[]$tree The menu link tree to manipulate.
Returns
[] The manipulated menu link tree.
generateIndexAndSort ( array  $tree)

Generates a unique index and sorts by it.

Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[]$tree The menu link tree to manipulate.
Returns
[] The manipulated menu link tree.
menuLinkCheckAccess ( MenuLinkInterface  $instance)
protected

Checks access for one menu link instance.

Parameters
\Drupal\Core\Menu\MenuLinkInterface$instanceThe menu link instance.
Returns
The access result.

References Drupal\accessManager(), AccessResult\allowed(), and MenuLinkInterface\getUrlObject().

Referenced by DefaultMenuLinkTreeManipulators\checkAccess().

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: