protected function CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs in Menu Link Weight 8
Same name and namespace in other branches
- 8.2 src/MenuParentFormSelector/CshsMenuParentFormSelector.php \Drupal\menu_link_weight\MenuParentFormSelector\CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs()
1 call to CshsMenuParentFormSelector::parentSelectOptionsTreeWalkCshs()
- CshsMenuParentFormSelector::getParentSelectOptionsCshs in src/
MenuParentFormSelector/ CshsMenuParentFormSelector.php
File
- src/
MenuParentFormSelector/ CshsMenuParentFormSelector.php, line 83
Class
- CshsMenuParentFormSelector
- Implements Client-side hierarchical select (CSHS) as the menu parent form selector.
Namespace
Drupal\menu_link_weight\MenuParentFormSelectorCode
protected function parentSelectOptionsTreeWalkCshs(array $tree, $menu_name, $indent, array &$options, $exclude, $depth_limit, CacheableMetadata &$cacheability = NULL) {
/** @var \Drupal\Core\Menu\MenuLinkTreeElement[] $tree */
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 = Unicode::truncate($link
->getTitle(), 30, TRUE, FALSE);
if (!$link
->isEnabled()) {
$title .= ' (' . $this
->t('disabled') . ')';
}
$options[$menu_name . ':' . $link
->getPluginId()] = [
'name' => $title,
'parent_tid' => $indent,
];
if (!empty($element->subtree)) {
$this
->parentSelectOptionsTreeWalkCshs($element->subtree, $menu_name, $menu_name . ':' . $link
->getPluginId(), $options, $exclude, $depth_limit, $cacheability);
}
}
}
}