protected function GroupContentMenuParentFormSelector::getMenuOptions in Group Content Menu 8
Gets a list of menu names for use as options.
Parameters
array $menu_names: (optional) Array of menu names to limit the options, or NULL to load all.
Return value
array Keys are menu names (ids) values are the menu labels.
Overrides MenuParentFormSelector::getMenuOptions
File
- src/
GroupContentMenuParentFormSelector.php, line 39
Class
- GroupContentMenuParentFormSelector
- Group content menu implementation of the menu parent form selector service.
Namespace
Drupal\group_content_menuCode
protected function getMenuOptions(array $menu_names = NULL) {
$entity_type = 'menu';
if ($this->isGroupMenu) {
$entity_type = 'group_content_menu';
}
$menus = $this->entityTypeManager
->getStorage($entity_type)
->loadMultiple($menu_names);
$options = [];
/** @var \Drupal\system\MenuInterface[] $menus */
foreach ($menus as $menu) {
if ($this->isGroupMenu) {
if ($route_group = \Drupal::routeMatch()
->getParameter('group')) {
$group_contents = $this->entityTypeManager
->getStorage('group_content')
->loadByEntity($menu);
if ($group_contents) {
$menu_group = array_pop($group_contents)
->getGroup();
if ($menu_group
->id() === $route_group
->id()) {
$options[GroupContentMenuInterface::MENU_PREFIX . $menu
->id()] = $menu
->label() . " ({$menu_group->label()})";
}
}
}
}
else {
$options[$menu
->id()] = $menu
->label();
}
}
return $options;
}