Skip to content

Configuration

A typical setup takes four steps. For example, to let editors preview the site without their Editor role, while only site administrators may also switch off the Staff role:

  1. Create a Toggler role with Toggle own unrestricted roles, and give it to the editors.
  2. Tick Restricted on the Staff role.
  3. Give the site administrators' role Toggle own restricted roles too.
  4. Place the Simple role toggler block in the front-end theme.

Permissions

At People > Permissions, grant one or both of:

Permission The user may switch off
Toggle own unrestricted roles the roles they hold that are not marked Restricted
Toggle own restricted roles the roles they hold that are marked Restricted

Each permission covers its own roles. A user with both may switch off any of their roles. A role that grants every permission, such as Administrator, counts as both.

Grant the permissions through a role of their own, such as Toggler, rather than through a role the user might switch off. The toggle permissions are kept while roles are switched off anyway, so the user can always switch them back on.

Restricted roles

On a role's edit form, the Restricted checkbox puts the role in the second set. Only users with Toggle own restricted roles can switch it off. For the others it stays on: the form shows it ticked and disabled, and offers them no Anonymous button, since the anonymous view would switch it off too.

Use it for the roles that must stay on for most users, such as a role that grants access to an intranet's content.

Giving users the switch

  • The Simple role toggler block shows the role form. Place it in the front-end theme, for example in the header. It shows only to users who may toggle, and it stays there while their roles are off, as the way back.
  • The Simple role toggler (icon) block shows an icon that opens the same form in a dialog, where the whole form would take too much room. The dialog is modal: the keyboard focus stays in it until it closes. Cancel, Escape or a click outside closes it and discards the changes.
  • The toolbar gets a Roles tab for users who keep the toolbar. Its label shows one letter per role, in capitals when the role is on. The tab needs the Toolbar module, in core on Drupal 11 and a contributed project on Drupal 12. Core's Navigation sidebar gets no tab: use a block there.
  • The page /admin/simple-role-toggler shows the form too.

The icon needs JavaScript to open its dialog. Without it, the icon is hidden, and the Simple role toggler block is the way to switch.

Settings

At Configuration > People > Simple role toggler (/admin/config/people/simple-role-toggler):

Setting Default What it does
Keep the toolbar and the navigation sidebar while roles are toggled off off When off, switching off the roles that grant them hides them too, and the block is the way back.
Forget the chosen roles when the user logs out on When on, logging out on purpose switches every role back on.
Let users switch their roles in one browser tab only off Adds Only in this tab to the form. See Roles in one tab.