diff --git a/src/Service/UWService.php b/src/Service/UWService.php index 3e0ffbbb5d97858b1cd94181fdc9d9e8dfcf9cf7..f2589f87350d8c9cdf641b44cecbfdc29129f93a 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -5,7 +5,6 @@ namespace Drupal\uw_cfg_common\Service; use Drupal\Core\Database\Connection; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Session\AccountInterface; use Drupal\node\NodeInterface; use Drupal\simplify_menu\MenuItems; @@ -418,24 +417,4 @@ class UWService implements UWServiceInterface { } } - /** - * Determine whether the user is in an administrator group. - * - * @param \Drupal\Core\Session\AccountInterface $user - * The user object. - * - * @return bool - * TRUE if the user is in an administrator group, FALSE otherwise. - */ - public static function userIsAdmin(AccountInterface $user): bool { - $user_roles = $user->getRoles(); - - // Based on core/modules/user/src/AccountSettingsForm.php. - $admin_roles = \Drupal::service('entity_type.manager')->getStorage('user_role')->getQuery() - ->condition('is_admin', TRUE) - ->execute(); - - return (bool) array_intersect($user_roles, $admin_roles); - } - } diff --git a/uw_cfg_common.module b/uw_cfg_common.module index 8741e9eb48e3321770e99fbfb59f26d149bd2b90..2ae720389b8a7180c46c5637abc7ebc0e9306e21 100644 --- a/uw_cfg_common.module +++ b/uw_cfg_common.module @@ -183,19 +183,8 @@ function uw_cfg_common_toolbar_alter(&$items) { return; } - // Get the roles of the user. - $roles = $current_user->getRoles(); - - // If there is only 1 role and that first role is authenticated, remove the - // manage link. If there are multiple roles then we know that they will have - // the Manage link, we are only removing the manage link for strictly - // authenticated users only. - if (count($roles) == 1 && $roles[0] == 'authenticated') { - // Remove the manage link. - unset($items['administration']); - } // Adjust toolbar for non-admin users. - elseif (!UWService::userIsAdmin($current_user)) { + if (!$current_user->hasPermission('access manage toolbar item')) { // Remove "Manage" toolbar item. unset($items['administration']); // Add links to "Workbench". 'dashboards' is renamed in diff --git a/uw_cfg_common.permissions.yml b/uw_cfg_common.permissions.yml index 0657662837eeba26772aa1c73e980fda8fa1bcb4..6426bcb64542f2ee674a522ce8c85d8fcac4cde1 100644 --- a/uw_cfg_common.permissions.yml +++ b/uw_cfg_common.permissions.yml @@ -8,6 +8,9 @@ title: 'Administer role expire configuration' description: 'Allows access to admin/config/system/role-expire.' restrict access: true +'access manage toolbar item': + title: 'Access "Manage" toolbar item' + description: 'Allows access to the toolbar item "Manage". Without this, "People" and "Reports" will appear under "Workbench" to those who have access.' 'bypass home page protection': title: 'Bypass home page protection' description: 'Allows taking actions that are not normally allowed for the home page, such as unpublishing.'