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
- Propose a working patch.
- Discuss and iterate.
User interface changes
No UX changes.
API changes
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | toolbar-refactor-1847198-74.patch.txt | 6.59 KB | jessebeach |
Comments
Comment #1
jessebeach commentedI'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.
Comment #1.0
jessebeach commentedadded some usage info
Comment #1.1
jessebeach commentedadded Tour module reference
Comment #2
jessebeach commentedTitle update
Comment #2.0
jessebeach commentedadded 1852346
Comment #3
jessebeach commentedSee 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?
Comment #4
caschbre commentedI'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.
Comment #4.0
caschbre commentedadded workbench
Comment #5
jessebeach commentedadding tags.
Comment #6
jessebeach commentedadding tags.
Comment #6.0
jessebeach commentedadded IIB http://drupal.org/project/iib
Comment #7
wim leersComment #8
scottrigbyAdded User Facing Navigation Bar.
Comment #18
nod_Could use some feedback from the mentionned projects about the integration with the toolbar.
Comment #24
smustgrave commentedClosing 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!