class MenuTreeParameters implements Serializable (View source)

Provides a value object to model menu tree parameters.

Menu tree parameters are used to determine the set of definitions to be loaded from \Drupal\Core\Menu\MenuTreeStorageInterface. Hence they determine the shape and content of the tree:

  • Which parent IDs should be used to restrict the tree. Only links with a parent in the list will be included.
  • Which menu links are omitted, depending on the minimum and maximum depth.

Properties

string $root

A menu link plugin ID that should be used as the root.

int|null $minDepth

The minimum depth of menu links in the resulting tree relative to the root.

int|null $maxDepth

The maximum depth of menu links in the resulting tree relative to the root.

string[] $expandedParents

An array of parent link IDs.

string[] $activeTrail

The IDs from the currently active menu link to the root of the whole tree.

array $conditions

The conditions used to restrict which links are loaded.

Methods

$this
setRoot(string $root)

Sets a root for menu tree loading.

$this
setMinDepth(int $min_depth)

Sets a minimum depth for menu tree loading.

$this
setMaxDepth(int $max_depth)

Sets a maximum depth for menu tree loading.

$this
addExpandedParents(array $parents)

Adds parent menu links IDs to restrict the tree.

$this
setActiveTrail(array $active_trail)

Sets the active trail IDs used to set the inActiveTrail property.

$this
addCondition(string $definition_field, mixed $value, string|null $operator = NULL)

Adds a custom query condition.

$this
onlyEnabledLinks()

Excludes links that are not enabled.

$this
setTopLevelOnly()

Ensures only the top level of the tree is loaded.

$this
excludeRoot()

Excludes the root menu link from the tree.

serialize()

{@inheritdoc}

unserialize($serialized)

{@inheritdoc}

array
__serialize()

{@inheritdoc}

void
__unserialize(array $data)

{@inheritdoc}

Details

$this setRoot(string $root)

Sets a root for menu tree loading.

Parameters

string $root

A menu link plugin ID, or empty string '' to use the root of the whole tree.

Return Value

$this

$this setMinDepth(int $min_depth)

Sets a minimum depth for menu tree loading.

Parameters

int $min_depth

The (root-relative) minimum depth to apply.

Return Value

$this

$this setMaxDepth(int $max_depth)

Sets a maximum depth for menu tree loading.

Parameters

int $max_depth

The (root-relative) maximum depth to apply.

Return Value

$this

$this addExpandedParents(array $parents)

Adds parent menu links IDs to restrict the tree.

Parameters

array $parents

An array containing parent IDs. If supplied, the tree is limited to links that have these parents.

Return Value

$this

$this setActiveTrail(array $active_trail)

Sets the active trail IDs used to set the inActiveTrail property.

Parameters

array $active_trail

An array containing the active trail: a list of menu link plugin IDs.

Return Value

$this

See also

MenuActiveTrail::getActiveTrailIds

$this addCondition(string $definition_field, mixed $value, string|null $operator = NULL)

Adds a custom query condition.

Parameters

string $definition_field

Only conditions that are testing menu link definition fields are allowed.

mixed $value

The value to test the link definition field against. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on the $operator.

string|null $operator

(optional) The comparison operator, such as =, <, or >=. It also accepts more complex options such as IN, LIKE, or BETWEEN. If NULL, defaults to the = operator.

Return Value

$this

Excludes links that are not enabled.

Return Value

$this

$this setTopLevelOnly()

Ensures only the top level of the tree is loaded.

Return Value

$this

$this excludeRoot()

Excludes the root menu link from the tree.

Note that this is only necessary when you specified a custom root, because the normal root ID is the empty string, '', which does not correspond to an actual menu link. Hence when loading a menu link tree without specifying a custom root the tree will start at the children even if this method has not been called.

Return Value

$this

serialize()

{@inheritdoc}

unserialize($serialized)

{@inheritdoc}

Parameters

$serialized

array __serialize()

{@inheritdoc}

Return Value

array

void __unserialize(array $data)

{@inheritdoc}

Parameters

array $data

Return Value

void