Jump to content
Robin S

Adding body classes to admin theme according to user role

Recommended Posts

This is something I used in a couple of modules recently and it could be useful as a standalone hook. It adds classes to the body tag in the admin theme for:

  • roles the user has
  • if the user is a non-superuser
  • the user's name

You could use this if you want to tweak the admin interface for a role using CSS/JS (e.g. with Admin Custom Files).

There is also an old wishlist item requesting this.

$this->addHookAfter('AdminTheme::getExtraMarkup', function($event) {
    $theme = $event->object;
    $user = $this->user;
    foreach($user->roles as $role) {
        $theme->addBodyClass("role-{$role->name}");
    }
    if(!$user->isSuperuser()) $theme->addBodyClass("role-nonsuperuser");
    $theme->addBodyClass("user-{$user->name}");
});

 

  • Like 4

Share this post


Link to post
Share on other sites

Would you mind if I add this to AdminOnSteroids? (probably won't be configurable)

  • Like 3

Share this post


Link to post
Share on other sites
4 minutes ago, tpr said:

Would you mind if I add this to AdminOnSteroids?

Go for it.

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...