How can I add a proprietary CSS class to the body element of the user that is being masqueraded?
I would like to have this functionality so that I can show messages that are usually hidden for a regular user so that I can see what's going on without the need of diving into the CSS in the Web Inspector of my browser.

Much obliged.

Comments

BassPlaya created an issue. See original summary.

avpaderno’s picture

Category: Feature request » Support request
ressa’s picture

Status: Active » Postponed

In an attempt to help the maintainers, I am going through some of the Drupal 7 issues, since it's EOL ... So thanks for making this request @bassplaya, is it still relevant for 2.x in Drupal 11?

bassplaya’s picture

@ressa, too long ago. I’m not sure if I ever have used it assuming this feature had been added.

ressa’s picture

Status: Postponed » Closed (outdated)

Thanks for a fast feedback, let's close it then.

I added the current language as a custom CSS class to my multilingual site arst.dk in Drupal 10 (Drupal's multilanguage support is spectacular) via Twig templates. First define the variable in a custom module:

function mymodule_preprocess(&$variables) {
  $current_language = \Drupal::languageManager()->getCurrentLanguage()->getId();
  switch ($current_language) {
    case $current_language == 'it':
      break;
    case $current_language == 'fr':
      break;
    default:
      $current_language = 'da';
    }
  $variables['page_language'] = 'lang-' . $current_language;
}

... then use in custom theme file html.html.twig like this, adding for example lang-fr:

{%
  set body_classes = [
    logged_in ? 'user-logged-in',
    page_language ? page_language,
  ]
%}

Good luck with the English teaching!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.