class GroupContentMenuParentFormSelector in Group Content Menu 8
Group content menu implementation of the menu parent form selector service.
The form selector is a list of all appropriate menu links.
Hierarchy
- class \Drupal\Core\Menu\MenuParentFormSelector implements MenuParentFormSelectorInterface uses DeprecatedServicePropertyTrait, StringTranslationTrait
- class \Drupal\group_content_menu\GroupContentMenuParentFormSelector
Expanded class hierarchy of GroupContentMenuParentFormSelector
File
- src/
GroupContentMenuParentFormSelector.php, line 13
Namespace
Drupal\group_content_menuView source
class GroupContentMenuParentFormSelector extends MenuParentFormSelector {
/**
* Determine if menu is a group menu.
*
* @var bool
*/
protected $isGroupMenu = FALSE;
/**
* {@inheritdoc}
*/
public function parentSelectElement($menu_parent, $id = '', array $menus = NULL) {
if (strpos($menu_parent, GroupContentMenuInterface::MENU_PREFIX) !== FALSE) {
$this->isGroupMenu = TRUE;
}
$element = parent::parentSelectElement($menu_parent, $id, $menus);
// Add the group content list tag in case a menu is created, deleted, etc.
$element['#cache']['tags'] = $element['#cache']['tags'] ?? [];
$element['#cache']['tags'] = Cache::mergeTags($element['#cache']['tags'], [
'group_content_list',
]);
return $element;
}
/**
* {@inheritdoc}
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
GroupContentMenuParentFormSelector:: |
protected | property | Determine if menu is a group menu. | |
GroupContentMenuParentFormSelector:: |
protected | function |
Gets a list of menu names for use as options. Overrides MenuParentFormSelector:: |
|
GroupContentMenuParentFormSelector:: |
public | function |
Gets a form element to choose a menu and parent. Overrides MenuParentFormSelector:: |
|
MenuParentFormSelector:: |
protected | property | ||
MenuParentFormSelector:: |
protected | property | The entity type manager service. | |
MenuParentFormSelector:: |
protected | property | The menu link tree service. | |
MenuParentFormSelector:: |
protected | function | Returns the maximum depth of the possible parents of the menu link. | |
MenuParentFormSelector:: |
public | function |
Gets the options for a select element to choose a menu and parent. Overrides MenuParentFormSelectorInterface:: |
|
MenuParentFormSelector:: |
protected | function | Iterates over all items in the tree to prepare the parents select options. | |
MenuParentFormSelector:: |
public | function | Constructs a \Drupal\Core\Menu\MenuParentFormSelector | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |