function simple_menu_permissions_preprocess_table in Simple Menu Permissions 8
Implements hook_preprocess_table().
Checks if the current user has the permission to view a menu in the menu list.
File
- ./
simple_menu_permissions.module, line 182 - Contains simple_menu_permissions.module.
Code
function simple_menu_permissions_preprocess_table(&$variables) {
$route_name = \Drupal::routeMatch()
->getRouteName();
if ($route_name && $route_name === 'entity.menu.collection') {
$account = \Drupal::currentUser()
->getAccount();
foreach ($variables['rows'] as $menu_id => $row_data) {
if (!$account
->hasPermission('view ' . $menu_id . ' menu in menu list')) {
unset($variables['rows'][$menu_id]);
}
}
$variables['empty'] = t('There are no @label yet, or you do not have the permission to view a menu.', [
'@label' => t('menus'),
]);
}
}