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

Core

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

Contrib

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

Comments

jessebeach’s picture

StatusFileSize
new6.59 KB

I'm porting this patch from #1847198-74: Update the structure returned by hook_toolbar(). It was posted after the code was committed. It's a good starting point for this issue.

jessebeach’s picture

Issue summary: View changes

added some usage info

jessebeach’s picture

Issue summary: View changes

added Tour module reference

jessebeach’s picture

Title: Leverage the plugin system to define toolbar items in order to sunset the custom hook_toolbar architecture » Make the Toolbar PHP and JavaScript API more flexible so that it enables contrib to leverage it

Title update

jessebeach’s picture

Issue summary: View changes

added 1852346

jessebeach’s picture

See also a conversation comparing Admin menu to the D8 Toolbar: #1847370: Why did I install admin_menu in favor of the Toolbar in Drupal 8?

caschbre’s picture

I'm coming from #1956204: Add Main Menu tab to add my scenario to this issue.

I'm attempting to provide two menus (Main Menu & Management) on the toolbar. The Management menu needs to check permissions before rendering it. The Main Menu should be able to use the ajax-magic that is currently in the D7 version to render the sub-tasks.

caschbre’s picture

Issue summary: View changes

added workbench

jessebeach’s picture

Issue tags: +sprint, +Spark

adding tags.

jessebeach’s picture

Issue tags: -sprint, -Spark +toolbar-followup

adding tags.

jessebeach’s picture

Issue summary: View changes
wim leers’s picture

Version: 8.0.x-dev » 8.1.x-dev
scottrigby’s picture

Issue summary: View changes

Added User Facing Navigation Bar.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

nod_’s picture

Status: Active » Postponed (maintainer needs more info)

Could use some feedback from the mentionned projects about the integration with the toolbar.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Category: Task » Feature request
Status: Postponed (maintainer needs more info) » Closed (outdated)

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!