diff --git a/core/modules/user/src/Hook/UserHooks.php b/core/modules/user/src/Hook/UserHooks.php index 4ed9f071a223e51b74bc2561a2028551e386c725..65a533d2a2a2ff16d5a7323703323a1b400974ae 100644 --- a/core/modules/user/src/Hook/UserHooks.php +++ b/core/modules/user/src/Hook/UserHooks.php @@ -10,6 +10,7 @@ use Drupal\Component\Assertion\Inspector; use Drupal\user\RoleInterface; use Drupal\Component\Render\PlainTextOutput; +use Drupal\Component\Utility\Html; use Drupal\Core\Session\AccountInterface; use Drupal\image\Plugin\Field\FieldType\ImageItem; use Drupal\Core\Render\Element; @@ -220,6 +221,12 @@ public function templatePreprocessDefaultVariablesAlter(&$variables): void { unset($variables['user']->pass, $variables['user']->sid, $variables['user']->ssid); $variables['is_admin'] = $user->hasPermission('access administration pages'); $variables['logged_in'] = $user->isAuthenticated(); + $roles = $user->getRoles(); + $all_roles = ''; + foreach ($roles as $role) { + $all_roles .= Html::cleanCssIdentifier($role) . '-role '; + } + $variables['roles'] = trim($all_roles); } /** diff --git a/core/themes/claro/templates/classy/layout/html.html.twig b/core/themes/claro/templates/classy/layout/html.html.twig index 48729c56e0571b36f71ebcfdbb7029748d13ba15..3a86c870880a6394944795e3b6871020836c4cab 100644 --- a/core/themes/claro/templates/classy/layout/html.html.twig +++ b/core/themes/claro/templates/classy/layout/html.html.twig @@ -5,6 +5,7 @@ * * Variables: * - logged_in: A flag indicating if user is logged in. + * - roles: The roles of the current user. * - root_path: The root path of the current page (e.g., node, admin, user). * - node_type: The content type for the current node, if the page is a node. * - head_title: List of text elements that make up the head_title variable. @@ -29,6 +30,7 @@ not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class, node_type ? 'page-node-type-' ~ node_type|clean_class, db_offline ? 'db-offline', + roles ? roles, ] %} <!DOCTYPE html> diff --git a/core/themes/olivero/templates/layout/html.html.twig b/core/themes/olivero/templates/layout/html.html.twig index 4558ab2a5f0e5e61b22846326bec15cd10b9c794..d5e0f87fac62b684f3cd643385e359e072b180e9 100644 --- a/core/themes/olivero/templates/layout/html.html.twig +++ b/core/themes/olivero/templates/layout/html.html.twig @@ -5,6 +5,7 @@ * * Variables: * - logged_in: A flag indicating if user is logged in. + * - roles: The roles of the current user. * - root_path: The root path of the current page (e.g., node, admin, user). * - node_type: The content type for the current node, if the page is a node. * - head_title: List of text elements that make up the head_title variable. @@ -31,6 +32,7 @@ not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class, node_type ? 'page-node-type-' ~ node_type|clean_class, db_offline ? 'db-offline', + roles ? roles, ] %} <!DOCTYPE html> diff --git a/core/themes/stable9/templates/layout/html.html.twig b/core/themes/stable9/templates/layout/html.html.twig index 0180ed85d9e325760334fa03a01ce4640232e873..2fed647738226a07bc2113462e9a6618452a5329 100644 --- a/core/themes/stable9/templates/layout/html.html.twig +++ b/core/themes/stable9/templates/layout/html.html.twig @@ -5,6 +5,7 @@ * * Variables: * - logged_in: A flag indicating if user is logged in. + * - roles: The roles of the current user. * - root_path: The root path of the current page (e.g., node, admin, user). * - node_type: The content type for the current node, if the page is a node. * - head_title: List of text elements that make up the head_title variable.