function MenuParentFormSelector::parentSelectOptionsTreeWalk
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::parentSelectOptionsTreeWalk()
- 10 core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::parentSelectOptionsTreeWalk()
- 11.x core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::parentSelectOptionsTreeWalk()
Iterates over all items in the tree to prepare the parents select options.
Parameters
\Drupal\Core\Menu\MenuLinkTreeElement[] $tree: The menu tree.
string $menu_name: The menu name.
string $indent: The indentation string used for the label.
array $options: The select options.
string $exclude: An excluded menu link.
int $depth_limit: The maximum depth of menu links considered for the select options.
\Drupal\Core\Cache\CacheableMetadata|null &$cacheability: The object to add cacheability metadata to, if not NULL.
1 call to MenuParentFormSelector::parentSelectOptionsTreeWalk()
- MenuParentFormSelector::getParentSelectOptions in core/
lib/ Drupal/ Core/ Menu/ MenuParentFormSelector.php - Gets the options for a select element to choose a menu and parent.
File
-
core/
lib/ Drupal/ Core/ Menu/ MenuParentFormSelector.php, line 141
Class
- MenuParentFormSelector
- Default implementation of the menu parent form selector service.
Namespace
Drupal\Core\MenuCode
protected function parentSelectOptionsTreeWalk(array $tree, $menu_name, $indent, array &$options, $exclude, $depth_limit, CacheableMetadata &$cacheability = NULL) {
foreach ($tree as $element) {
if ($element->depth > $depth_limit) {
// Don't iterate through any links on this level.
break;
}
// Collect the cacheability metadata of the access result, as well as the
// link.
if ($cacheability) {
$cacheability = $cacheability->merge(CacheableMetadata::createFromObject($element->access))
->merge(CacheableMetadata::createFromObject($element->link));
}
// Only show accessible links.
if (!$element->access
->isAllowed()) {
continue;
}
$link = $element->link;
if ($link->getPluginId() != $exclude) {
$title = $indent . ' ' . Unicode::truncate($link->getTitle(), 30, TRUE, FALSE);
if (!$link->isEnabled()) {
$title .= ' (' . $this->t('disabled') . ')';
}
$options[$menu_name . ':' . $link->getPluginId()] = $title;
if (!empty($element->subtree)) {
$this->parentSelectOptionsTreeWalk($element->subtree, $menu_name, $indent . '--', $options, $exclude, $depth_limit, $cacheability);
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.