MenuTreeParameters
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
Sets a root for menu tree loading.
Sets a minimum depth for menu tree loading.
Sets a maximum depth for menu tree loading.
Adds parent menu links IDs to restrict the tree.
Sets the active trail IDs used to set the inActiveTrail property.
Adds a custom query condition.
Excludes links that are not enabled.
Ensures only the top level of the tree is loaded.
Excludes the root menu link from the tree.
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Details
$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.
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.
serialize()
{@inheritdoc}
unserialize($serialized)
{@inheritdoc}
array
__serialize()
{@inheritdoc}
void
__unserialize(array $data)
{@inheritdoc}