protected function NodeFormAlter::getGroupMenus in Group Content Menu 8
Get an array of GroupContentMenus.
Parameters
\Drupal\group\Entity\GroupInterface[] $groups: An array of groups to get menus for.
Return value
array An array of GroupContentMenu labels, keyed by menu link id..
1 call to NodeFormAlter::getGroupMenus()
- NodeFormAlter::alter in src/
NodeFormAlter.php - Alter node forms to add GroupContentMenu options where appropriate.
File
- src/
NodeFormAlter.php, line 265
Class
- NodeFormAlter
- Helper class to handle altering node forms.
Namespace
Drupal\group_content_menuCode
protected function getGroupMenus(array $groups) {
$group_menus = [];
foreach ($groups as $group) {
$group_menus[] = array_map(static function (GroupContentInterface $group_content) {
$id = GroupContentMenuInterface::MENU_PREFIX . $group_content
->getEntity()
->id();
return [
$id => $group_content
->getEntity()
->label() . " ({$group_content->getGroup()->label()})",
];
}, group_content_menu_get_menus_per_group($group));
}
// Unpack the group menus.
$group_menus = array_merge(...$group_menus);
// We have multiple levels of nested arrays, depending on if any groups
// have menus or not.
if ($group_menus) {
$group_menus = array_merge(...$group_menus);
}
return array_unique($group_menus);
}