function groupmenu_preprocess_menu in Group Menu 8
Implements hook_preprocess_menu().
Hides group menu's from admin menu.
File
- ./
groupmenu.module, line 187 - Gives the ability to create and manage menus for groups.
Code
function groupmenu_preprocess_menu(&$variables) {
if (empty($variables['items'])) {
return;
}
// Ensure that menu_name exists.
if (!isset($variables['menu_name'])) {
// In rare cases (for unknown reasons) menu_name may not be set.
// As fallback, we can fetch it from the first menu item.
$variables['menu_name'] = NULL;
$first_link = reset($variables['items']);
if (isset($first_link['original_link'])) {
$variables['menu_name'] = $first_link['original_link']
->getMenuName();
}
}
if ($variables['menu_name'] == 'admin') {
// Get group types that enabled group menu's.
$plugin_id = 'group_menu:menu';
$group_content_types = \Drupal::entityTypeManager()
->getStorage('group_content_type')
->loadByProperties([
'content_plugin' => $plugin_id,
]);
if (empty($group_content_types)) {
return;
}
_groupmenu_filter_admin_links($variables['items'], $group_content_types);
}
}