Home link added when using Toolbar Menu

Created on 24 July 2023, over 1 year ago
Updated 20 June 2024, 6 months ago

Problem/Motivation

Alongside Gin and Gin Toolbar, I want to use Toolbar Menu in order to provide a carefully crafted admin UX for content editors.
Toolbar Menu allows me to add custom menu items on the admin toolbar.
If I have a custom toolbar menu while Gin Toolbar module is also enabled, Gin Toolbar injects an unnecessary "Home" menu item on each menu.

Steps to reproduce

- Install Gin, set it as admin theme and choose the classic toolbar (This is only to not encounter this issue https://www.drupal.org/project/toolbar_menu/issues/3271757 🐛 css class name conflict with gin theme Needs review )
- Install and enable Toolbar Menu and create a toolbar menu: such menu is now visible in the admin toolbar, with the correct menu items
- Install and enable Gin Toolbar: the same menu now displays an extra "Home" (behind an missing icon) which is not present in the source menu.

Proposed resolution

The Home icon is "injected" in the gin_toolbar template which reference the gin/templates/navigation/menu--toolbar--gin.html.twig on line 50, with the comment "Add Home if it doesn't exist", using the following condition:
{% if menu_level == 0 and loop.index == 1 and item.gin_id != 'admin_toolbar_tools-help' %}.
I'm not sure exactly where this is needed since i tried to disable the snippet entirely and all the admin menu look good, even without Admin Toolbar Extras. To note that item.gin_id for the custom toolbar menu is empty.
I therefore propose to adjust the condition by adding item.gin_id is not empty.
Full statement:
{% if menu_level == 0 and loop.index == 1 and item.gin_id is not empty and item.gin_id != 'admin_toolbar_tools-help' %}

Something else to note, in an earlier version of the same template the condition was set simply to {% if menu_name == 'admin' %}. At the moment, I don't have enough context to understand why this item is added. It would be handy explain why we're adding it in the comment above.

Remaining tasks

None

User interface changes

The Home icon menu won't be visible anymore in custom menu, which is presumably correct.

API changes

None

Data model changes

None

Screenshot

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇦🇺Australia elgandoz Canberra

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024