function toolbar_toolbar

Same name in other branches
  1. 9 core/modules/toolbar/toolbar.module \toolbar_toolbar()
  2. 8.9.x core/modules/toolbar/toolbar.module \toolbar_toolbar()
  3. 11.x core/modules/toolbar/toolbar.module \toolbar_toolbar()

Implements hook_toolbar().

File

core/modules/toolbar/toolbar.module, line 138

Code

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,
            ],
        ],
        '#wrapper_attributes' => [
            'class' => [
                'home-toolbar-tab',
            ],
        ],
        '#attached' => [
            'library' => [
                'toolbar/toolbar.escapeAdmin',
            ],
        ],
        '#weight' => -20,
    ];
    // To conserve bandwidth, we only include the top-level links in the HTML.
    // The subtrees are fetched through a JSONP script that is generated at the
    // toolbar_subtrees route. We provide the JavaScript requesting that JSONP
    // script here with the hash parameter that is needed for that route.
    // @see toolbar_subtrees_jsonp()
    [
        $hash,
        $hash_cacheability,
    ] = _toolbar_get_subtrees_hash();
    $subtrees_attached['drupalSettings']['toolbar'] = [
        'subtreesHash' => $hash,
    ];
    // The administration element has a link that is themed to correspond to
    // a toolbar tray. The tray contains the full administrative menu of the site.
    $items['administration'] = [
        '#type' => 'toolbar_item',
        'tab' => [
            '#type' => 'link',
            '#title' => t('Manage'),
            '#url' => Url::fromRoute('system.admin'),
            '#attributes' => [
                'title' => t('Admin menu'),
                'class' => [
                    'toolbar-icon',
                    'toolbar-icon-menu',
                ],
                // A data attribute that indicates to the client to defer loading of
                // the admin menu subtrees until this tab is activated. Admin menu
                // subtrees will not render to the DOM if this attribute is removed.
                // The value of the attribute is intentionally left blank. Only the
                // presence of the attribute is necessary.
'data-drupal-subtrees' => '',
            ],
        ],
        'tray' => [
            '#heading' => t('Administration menu'),
            '#attached' => $subtrees_attached,
            'toolbar_administration' => [
                '#pre_render' => [
                    [
                        ToolbarController::class,
                        'preRenderAdministrationTray',
                    ],
                ],
                '#type' => 'container',
                '#attributes' => [
                    'class' => [
                        'toolbar-menu-administration',
                    ],
                ],
            ],
        ],
        '#weight' => -15,
    ];
    $hash_cacheability->applyTo($items['administration']);
    return $items;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.