Make the Toolbar PHP and JavaScript API more flexible so that it enables contrib to leverage it

Created on 21 January 2013, over 11 years ago
Updated 8 February 2023, over 1 year ago

Problem/Motivation

Issue #1847198: Update the structure returned by hook_toolbar() is an intermediary step between the initial, simple architecture of hook_toolbar and ultimately the flexible, easy to use architecture that we know is possible. Many of the improvements proposed in this ticket were originally suggest by sun in #1847198-62: Update the structure returned by hook_toolbar() .

Any solution we put together should take this issue into account: #1852346: [discussion, no patch] Toolbar UI regression: shortcuts and menu not visible at same time

Modules that will require integration with Toolbar

Contextual
Menu (?)
Search (?)
Shortcut
Tour
User

I10n_client: http://drupal.org/project/l10n_client
Interactive Information Bar (IIB): http://drupal.org/project/iib
Responsive Preview: http://drupal.org/project/responsive_preview
User Facing Navigation Bar: https://www.drupal.org/project/navbar_userfacing
Workbench: http://drupal.org/project/workbench

Proposed resolution

In #1847198-62: Update the structure returned by hook_toolbar() , sun asks:

Why aren't the toolbar tabs/items not plugins, just like toolbar tray/block content plugins, too?

And provides the following stub code:

<?php
core/modules/user/lib/Drupal/user/Plugin/toolbar/tab/Account.php:

namespace Drupal/user/Plugin/toolbar/tab;

use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Menu\MenuBlock;
use Drupal\toolbar\ToolbarTab;

/**
 * User account toolbar tab.
 *
 * @Plugin(
 *   id = "user_account",
 *   label = @Translation("User account"),
 *   module = "user",
 *   renderTrayWithTab = false
 * )
 */
class Account extends ToolbarTab {

  /**
   * Implements ToolbarTabInterface::access().
   */
  public function access() {
    // Only applicable to authenticated users.
    return !empty($GLOBALS['user']->uid);
  }

  /**
   * Implements ToolbarTabInterface::buildTab().
   */
  public function buildTab() {
    $build = array(
      '#...' => '...',
    );
    return $build;
  }

  /**
   * Implements ToolbarTabInterface::buildTray().
   */
  public function buildTray() {
    $settings = array(
      'menu_name' => 'account',
      'max_depth' => 1,
    );
    return new MenuBlock($settings);
  }

}
?>

Ideally, but moving toolbar item/tray declarations to plugins, we can leverage existing content via blocks already defined in Drupal, e.g. menus.

What we're looking to do here is further refine the toolbar item declaration architecture so it leverages more sub-systems and uses less custom code.

Remaining tasks

  1. Propose a working patch.
  2. Discuss and iterate.

User interface changes

No UX changes.

API changes

TBD

Feature request
Status

Closed: outdated

Version

10.1

Component
Toolbar 

Last updated about 11 hours ago

  • Maintained by
  • 🇫🇷France @nod_
Created by

🇺🇸United States jessebeach

Live updates comments and jobs are added and updated live.
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 States smustgrave

    Closing this as outdated as additional information was requested in #18 3 years ago.

    If still a valid task please reopen addressing the point and updating issue summary following the default template.

    Thanks!

Production build 0.71.5 2024