public function MenuParentFormSelector::getParentSelectOptions in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Menu/MenuParentFormSelector.php \Drupal\Core\Menu\MenuParentFormSelector::getParentSelectOptions()
Gets the options for a select element to choose a menu and parent.
Parameters
string $id: Optional ID of a link plugin. This will exclude the link and its children from the select options.
array $menus: Optional array of menu names as keys and titles as values to limit the select options. If NULL, all menus will be included.
\Drupal\Core\Cache\CacheableMetadata|null &$cacheability: Optional cacheability metadata object, which will be populated based on the accessibility of the links and the cacheability of the links.
Return value
array Keyed array where the keys are contain a menu name and parent ID and the values are a menu name or link title indented by depth.
Overrides MenuParentFormSelectorInterface::getParentSelectOptions
1 call to MenuParentFormSelector::getParentSelectOptions()
- MenuParentFormSelector::parentSelectElement in core/
lib/ Drupal/ Core/ Menu/ MenuParentFormSelector.php - Gets a form element to choose a menu and parent.
File
- core/
lib/ Drupal/ Core/ Menu/ MenuParentFormSelector.php, line 66
Class
- MenuParentFormSelector
- Default implementation of the menu parent form selector service.
Namespace
Drupal\Core\MenuCode
public function getParentSelectOptions($id = '', array $menus = NULL, CacheableMetadata &$cacheability = NULL) {
if (!isset($menus)) {
$menus = $this
->getMenuOptions();
}
$options = [];
$depth_limit = $this
->getParentDepthLimit($id);
foreach ($menus as $menu_name => $menu_title) {
$options[$menu_name . ':'] = '<' . $menu_title . '>';
$parameters = new MenuTreeParameters();
$parameters
->setMaxDepth($depth_limit);
$tree = $this->menuLinkTree
->load($menu_name, $parameters);
$manipulators = [
[
'callable' => 'menu.default_tree_manipulators:checkNodeAccess',
],
[
'callable' => 'menu.default_tree_manipulators:checkAccess',
],
[
'callable' => 'menu.default_tree_manipulators:generateIndexAndSort',
],
];
$tree = $this->menuLinkTree
->transform($tree, $manipulators);
$this
->parentSelectOptionsTreeWalk($tree, $menu_name, '--', $options, $id, $depth_limit, $cacheability);
}
return $options;
}