My main menu has 2 levels of items (menu and submenu), but the user toolbar only displays the first level.

The administration user toolbar does a good job at displaying 2 levels on a computer and even 3 levels in trays when the menu switches to vertical on a mobile (see cap) . Would it be possible to have the same behaviour?

Comments

juliencarnot created an issue. See original summary.

eme’s picture

+1

It would be great to use this module in conjuction with Admin Toolbar (I'm co-maintainer of the module) to define administration menus depending for exemple on certain roles (for exemple a menu for contributors).

vpeltot’s picture

Status: Active » Needs review
StatusFileSize
new5.66 KB

Great Ideas !
This patch updates my module to add a compatibility with admin_toolbar (multi level menu + add specific classes to work with admin_toolbar properly).

@juliencarnot @eme can you test this patch ?

To test :
1. Apply this patch
2. Enable admin_toolbar
3. Create a menu with multi level / or add "administration" (currently multi level) menu in the toolbar

Normally you should see a multi level menu in toolbar.

@eme If is ok for you, I will add a reference + explanation to admin_toolbar module in my project page.
And if you can promote mine, it will be awesome !

juliencarnot’s picture

I applied the patch, but as soon as I added a menu to the toolbar, I got this message:
InvalidArgumentException: Class "toolbar_menu.menu_link_tree_manipulators" does not exist. in Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (line 29 of core/lib/Drupal/Core/DependencyInjection/ClassResolver.php).

juliencarnot’s picture

Sorry, missed the pmu before re-enabling, I don't have the error anymore. However, I added my main menu and the administration menu to the toolbar and I don't see any sublevel entries...

vpeltot’s picture

@juliencarnot
Have you downloaded and enabled "admin_toolbar" menu?

juliencarnot’s picture

Ok, I missed that too! ;-). Hovering over the items show the subitems in a dropdownmenu on a large screen. However, I don't get the rendering of all items and subitems on a smaller screen I was hoping for when the toolbar switches to vertical mode (see screen capture admintoolbar.png for example).

vpeltot’s picture

StatusFileSize
new6.4 KB

The toolbar display on a smaller screen is manage by drupal itself, and by default each item is displayed like an icon.

Bug found:
When the toolbar is displayed on the left, the multi level doesn't work

Here comes a new patch with a to fix this.

@eme
Have you a moment to test this patch ?

juliencarnot’s picture

Thanks @vpeltot!
Works perfectly for me!

vpeltot’s picture

Status: Needs review » Needs work

Argh :/

Bug found.
When I disable admin_toolbar, the drupal responsive dropdown toolbar (sticky on the left) doesn't work perfectly :

  • The button for the third level doesn't work
  • If I refresh the page with any toolbar_menu item active, the "Manage" toolbar is broken. All items are on single level mode
juliencarnot’s picture

Ouch. Didn't notice the third level issue, but reproduced the second point from time to time, not sure if caching is hiding it when it appears to work.

Another issue: adding the toolbar for the authentified users only resulted in blocking all javascript execution for anonymous visitors. "Drupal not defined" says the JS console...

vpeltot’s picture

I found where is the problem.

Drupal calls a JS present in toolbar.js to render the collapsible toolbar.

        // Render collapsible menus.
        var menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
        Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
          el: $(this).find('.toolbar-menu-administration').get(0),
          model: menuModel,
          strings: options.strings
        });

and more specificaly

el: $(this).find('.toolbar-menu-administration').get(0),

Only the first toolbar element with the class 'toolbar-menu-administration' is rendered.

I tried to remove the .get(0), everything works fine without this code.

I don't like Javascript, and he don't like me !
So, how can I rewrite the Drupal.toolbar.views.menuVisualView object ?
Any idea ?

vpeltot’s picture

Status: Needs work » Needs review
StatusFileSize
new8.78 KB

I found !

Here a new patch.
Everything should works now.

eme’s picture

It works very well indeed ! Congrats.

  • vpeltot committed 08fde4c on 8.x-1.x
    Issue #2658710 by vpeltot: Display all levels from the menu in the...
vpeltot’s picture

Status: Needs review » Closed (fixed)

Patch merged !
Thanks guys !

eme’s picture

Linked from Admin toolbar module page as it plays quite nicely now :-)