Add unmasquerade compatibility for new core navigation module

Created on 10 July 2024, 5 months ago

Problem/Motivation

When using the new core navigation module, there seems to be no way to unmasquerade after you masquerade

Steps to reproduce

Disable any of the following modules if they are currently installed:

  • toolbar
  • gin_toolbar
  • admin_toolbar
  • admin_toolbar_tools
  • admin_toolbar_links_access_filter

Enable the following core modules:

  • navigation
  • navigation_top_bar

Place the masquerade block where you can see it via the Structure -> Blocks admin page.
Now you can see the masquerade block and you can masquerade. But after that, there is no way to unmasquerade.

Proposed resolution

There are a few places where an unmasquerade option can be added, like:

  1. Add a unmasquerade link in the account menu in the Navigation (the last thing on the bottom of the vertical navigation toolbar on the left shows your username with edit profile and logout links: add a unmasquerade link here)
  2. Add a unmasquarade link in the new Navigation Top Bar (under 'More actions' on top of the page
  3. Add settings to the masquerade block so it can show an unmasquerade button
  4. Add a new unmasquerade block you could place just like the masquerade block

Option number one seems the most logical place for me.

Remaining tasks

Create patch, review, commit

User interface changes

Probably an extra link inside the user menu inside the new Navigation vertical toolbaar

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇧🇪Belgium flyke

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @flyke
  • 🇧🇪Belgium flyke

    Added a patch.

  • Status changed to Needs review 5 months ago
  • 🇫🇷France andypost

    Thank you! Great integration to add!
    Let's get more opinions on a way to integrate, for example https://docs.gitlab.com/ee/administration/admin_area.html#user-impersona...

    +++ b/masquerade.module
    @@ -254,3 +254,20 @@ function masquerade_migration_plugins_alter(array &$migrations) {
    +function masquerade_preprocess_menu_region__footer(array &$variables): void {
    +  if (\Drupal::service('masquerade')->isMasquerading()) {
    +    $variables['items']['masquerade_switch_back'] = [
    +      'title' => t('Unmasquerade'),
    +      'url' => Url::fromRoute('masquerade.unmasquerade'),
    

    Curios if it needs cache metadata?!

    Moreover we can display the block with quick links and so on.

    Is there a way to configure how to display in navigation as I know nothing about it's API

  • 🇧🇪Belgium flyke

    I'm afraid I don't know much about the experimental Navigation module, but I am testing it out in a few projects to replace Gin Toolbar and Toolbar modules. I dumped all the $variables via hook_preprocess_navigation and hook_preprocess_navigation_menu and hook_preprocess_menu_region__footer but I see nothing about caching. Also missing is a 'weight' value or something, so adjusting the order is done by adjusting the order of the indexes in the ['items'] array itself.

    So to answer your questions:
    Curios if it needs cache metadata?!
    I don't think that is something you can set in the Navigation items

    Moreover we can display the block with quick links and so on.
    I'm not sure what you mean by this ?

    Is there a way to configure how to display in navigation as I know nothing about it's API
    Not that I know, you just add an item to ['items'] that is an array like this:

        $variables['items']['navigation.my_views_page'] = [
          'is_expanded' => FALSE,
          'is_collapsed' => FALSE,
          'in_active_trail' => FALSE,
          'title' => t('My view page'),
          'url' => Url::fromRoute('view.mycustomview.page_&'),
          'below' => [],
          'class' => 'navigation_content',
        ];

    The class decides the icon. So easiest is to use existing classes and icons. But I have created items with a custom class and attached a library to add a CSS to set custom icon for the custom class.

  • 🇨🇷Costa Rica mcortes19

    I added the masquerade cache context to the main region footer menu

Production build 0.71.5 2024