Gin theme breaks custom toolbar items

Created on 27 March 2024, 8 months ago

Problem/Motivation

We have a custom admin toolbar item in Drupal 10.2.4, added via hook_toolbar, as per the instructions here https://drupal.stackexchange.com/a/215404.

Literally this:

function module_name_toolbar() {
    $items = [];
    $items['module_name'] = [
        '#cache' => [
            'contexts' => [
                'user.permissions',
            ],
        ],
    ];
    $items['module_name'] += array(
        '#type' => 'toolbar_item',
        'tab' => [
            '#type' => 'html_tag',
            '#tag' => 'button',
            '#value' => t('Title'),
            '#attributes' => array(
                'class' => array('toolbar-icon', 'toolbar-icon-help', 'toolbar-item'),
                'aria-pressed' => 'false',
                'type' => 'button',
                'title' => 'hover text',
            ),
        ],
        '#wrapper_attributes' => [
            'class' => [
                'toolbar-tab'
            ],
            'id' => 'toolbar-tab-docs',
        ],
        '#attached' => array(
            'library' => array(
                'module_name/library_name
            ),
        ),
    );
    return $items;
}

.. and the JS code, which just performs a simple redirect:

(function ($) {
    $( "#toolbar-tab-docs" ).click(function() {
        console.log("the link was hit");
        window.open("/some/redirect", "_blank");
    });
})(jQuery);

it works fine until we enable Gin theme whereupon the link stops responding - it doesn't even fire the Javascript.

Steps to reproduce

  1. Install Drupal 10.2.4.
  2. Add the above code in a custom .module file, enable the module
  3. Test the link - it works
  4. Enable the latest Gin theme RC (9)
  5. Test the link - it doesn't even log to the console.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Closed: works as designed

Component

User interface

Created by

🇬🇧United Kingdom eastdrive

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

Comments & Activities

  • Issue created by @eastdrive
  • 🇨🇭Switzerland saschaeggi Zurich

    Gin does not include any jQuery libraries. You will likely need to load them manually. As jQuery is deprecated in Drupal core you might want to refactor your code.

    Also make sure you attach your JS to Gin's toolbar library so it gets loaded when we load the toolbar.

    Cheers

  • Status changed to Closed: works as designed 8 months ago
  • 🇨🇭Switzerland saschaeggi Zurich
Production build 0.71.5 2024