interface MenuLinkTreeInterface

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php \Drupal\Core\Menu\MenuLinkTreeInterface
  2. 8.9.x core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php \Drupal\Core\Menu\MenuLinkTreeInterface
  3. 10 core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php \Drupal\Core\Menu\MenuLinkTreeInterface

Defines an interface for loading, transforming and rendering menu link trees.

The main purposes of this interface are:

Hierarchy

Expanded class hierarchy of MenuLinkTreeInterface

All classes that implement MenuLinkTreeInterface

8 files declare their use of MenuLinkTreeInterface
LinksetController.php in core/modules/system/src/Controller/LinksetController.php
MenuForm.php in core/modules/menu_ui/src/MenuForm.php
MenuLinkDepthConstraintValidator.php in core/lib/Drupal/Core/Menu/Plugin/Validation/Constraint/MenuLinkDepthConstraintValidator.php
ModuleAdminLinksHelper.php in core/modules/system/src/ModuleAdminLinksHelper.php
SystemAdminMenuBlockAccessCheck.php in core/modules/system/src/Access/SystemAdminMenuBlockAccessCheck.php

... See full list

File

core/lib/Drupal/Core/Menu/MenuLinkTreeInterface.php, line 26

Namespace

Drupal\Core\Menu
View source
interface MenuLinkTreeInterface {
  
  /**
   * Gets the link tree parameters for rendering a specific menu.
   *
   * Builds menu link tree parameters that:
   * - Expand all links in the active trail based on route being viewed.
   * - Expand the descendants of the links in the active trail whose
   *   'expanded' flag is enabled.
   *
   * This only sets the (relatively complex) parameters to achieve the two above
   * goals, but you can still further customize these parameters.
   *
   * @param string $menu_name
   *   The menu name, needed for retrieving the active trail and links with the
   *   'expanded' flag enabled.
   *
   * @return \Drupal\Core\Menu\MenuTreeParameters
   *   The parameters to determine which menu links to be loaded into a tree.
   *
   * @see \Drupal\Core\Menu\MenuTreeParameters
   */
  public function getCurrentRouteMenuTreeParameters($menu_name);
  
  /**
   * Loads a menu tree with a menu link plugin instance at each element.
   *
   * There will be no sorting or access checks. For that, use ::transform().
   *
   * @param string $menu_name
   *   The name of the menu.
   * @param \Drupal\Core\Menu\MenuTreeParameters $parameters
   *   The parameters to determine which menu links to be loaded into a tree.
   *
   * @return \Drupal\Core\Menu\MenuLinkTreeElement[]
   *   A menu link tree.
   */
  public function load($menu_name, MenuTreeParameters $parameters);
  
  /**
   * Applies menu link tree manipulators to transform the given tree.
   *
   * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
   *   The menu tree to manipulate.
   * @param array $manipulators
   *   The menu link tree manipulators to apply. Each is an array with keys:
   *   - callable: a callable or a string that can be resolved to a callable
   *     by Drupal\Core\Utility\CallableResolver::getCallableFromDefinition()
   *   - args: optional array of arguments to pass to the callable after $tree.
   *   For example, to sort and check access:
   *   @code
   *   $manipulators = [
   *     ['callable' => 'menu.default_tree_manipulators:checkNodeAccess'],
   *     ['callable' => 'menu.default_tree_manipulators:checkAccess'],
   *     ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
   *   ];
   *   @endcode
   *
   * @return \Drupal\Core\Menu\MenuLinkTreeElement[]
   *   The manipulated menu link tree.
   */
  public function transform(array $tree, array $manipulators);
  
  /**
   * Builds a renderable array from a menu tree.
   *
   * The menu item's LI element is given one of the following classes:
   * - expanded: The menu item is showing its submenu.
   * - collapsed: The menu item has a submenu that is not shown.
   * - leaf: The menu item has no submenu.
   *
   * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree
   *   A data structure representing the tree, as returned from
   *   MenuLinkTreeInterface::load().
   *
   * @return array
   *   A renderable array.
   */
  public function build(array $tree);
  
  /**
   * Returns the maximum depth of tree that is supported.
   *
   * @return int
   *   The maximum depth.
   */
  public function maxDepth();
  
  /**
   * Finds the height of a subtree rooted by of the given ID.
   *
   * @param string $id
   *   The ID of an item in the storage.
   *
   * @return int
   *   Returns the height of the subtree. This will be at least 1 if the ID
   *   exists, or 0 if the ID does not exist in the storage.
   */
  public function getSubtreeHeight($id);
  
  /**
   * Finds expanded links in a menu given a set of possible parents.
   *
   * @param string $menu_name
   *   The menu name.
   * @param array $parents
   *   One or more parent IDs to match.
   *
   * @return array
   *   The menu link IDs that are flagged as expanded in this menu.
   */
  public function getExpanded($menu_name, array $parents);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
MenuLinkTreeInterface::build public function Builds a renderable array from a menu tree. 1
MenuLinkTreeInterface::getCurrentRouteMenuTreeParameters public function Gets the link tree parameters for rendering a specific menu. 1
MenuLinkTreeInterface::getExpanded public function Finds expanded links in a menu given a set of possible parents. 1
MenuLinkTreeInterface::getSubtreeHeight public function Finds the height of a subtree rooted by of the given ID. 1
MenuLinkTreeInterface::load public function Loads a menu tree with a menu link plugin instance at each element. 1
MenuLinkTreeInterface::maxDepth public function Returns the maximum depth of tree that is supported. 1
MenuLinkTreeInterface::transform public function Applies menu link tree manipulators to transform the given tree. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.