class MenuLinkTreeElement (View source)

Provides a value object to model an element in a menu link tree.

\Drupal\Core\Menu\MenuLinkTreeElement objects represent a menu link's data. Objects of this class provide complimentary data: the placement in a tree. Therefore, we can summarize this split as follows:

  • Menu link objects contain all information about an individual menu link, plus what their parent is. But they don't know where exactly in a menu link tree they live.
  • Instances of this class are complimentary to those objects, they know:
    • All additional metadata from {menu_tree}, which contains "materialized" metadata about a menu link tree, such as whether a link in the tree has visible children and the depth relative to the root.
    • Plus all additional metadata that's adjusted for the current tree query, such as whether the link is in the active trail, whether the link is accessible for the current user, and the link's children (which are only loaded if the link was marked as "expanded" by the query).

Properties

$link

The menu link for this element in a menu link tree.

MenuLinkTreeElement[] $subtree

The subtree of this element in the menu link tree (this link's children).

int $depth

The depth of this link relative to the root of the tree.

bool $hasChildren

Whether this link has any children at all.

bool $inActiveTrail

Whether this link is in the active trail.

AccessResultInterface|null $access

Whether this link is accessible by the current user.

$options

Additional options for this link.

Methods

__construct(MenuLinkInterface $link, bool $has_children, int $depth, bool $in_active_trail, array $subtree)

Constructs a new \Drupal\Core\Menu\MenuLinkTreeElement.

int
count()

Counts all menu links in the current subtree.

Details

__construct(MenuLinkInterface $link, bool $has_children, int $depth, bool $in_active_trail, array $subtree)

Constructs a new \Drupal\Core\Menu\MenuLinkTreeElement.

Parameters

MenuLinkInterface $link

The menu link for this element in the menu link tree.

bool $has_children

A flag as to whether this element has children even if they are not included in the tree (i.e. this may be TRUE even if $subtree is empty).

int $depth

The depth of this element relative to the tree root.

bool $in_active_trail

A flag as to whether this link was included in the list of active trail IDs used to build the tree.

array $subtree

The children of this element in the menu link tree.

int count()

Counts all menu links in the current subtree.

Return Value

int

The number of menu links in this subtree (one plus the number of menu links in all descendants).