hook_toolbar example defines the classes in the wrong location

Created on 17 January 2015, almost 10 years ago
Updated 6 March 2024, 9 months ago

When the class is defined in ['#options']['attributes']['class'] instead of ['#attributes']['class'] it replaces the classes that ToolbarItem adds in preRenderToolbarItem causing the toolbar item to render incorrectly.

Updated the example so that module developers don't run into this if they use this particular example.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Toolbar 

Last updated about 9 hours ago

  • Maintained by
  • 🇫🇷France @nod_
Created by

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom joachim

    I don't understand what's going on with this issue.

    The IS and patch #12 say that this is about documentation and patch 12 is a fix to api.php documentation.

    Then patch 14 is TOTALLY different and changes a test!!!

    Also, I did a quick test, and BOTH ways of setting a class work:

    function toolbar_toolbar() {
      // The 'Home' tab is a simple link, with no corresponding tray.
      $items['home'] = [
        '#type' => 'toolbar_item',
        'tab' => [
          '#type' => 'link',
          '#title' => t('Back to site'),
          '#url' => Url::fromRoute('<front>'),
          '#attributes' => [
            'title' => t('Return to site content'),
            'class' => ['toolbar-icon', 'toolbar-icon-escape-admin'],
            'data-toolbar-escape-admin' => TRUE,
          ],
          '#options' => [
            'attributes' => [
              'title' => t('Home page'),
              'class' => ['toolbar-icon', 'toolbar-icon-THIS-WORKS-TOO-and-overrides-#attributes'],
            ],
          ],
        ],
    

    Though the docs should reflect what is current usage, which is what patch #12 is doing.

Production build 0.71.5 2024