Follow-up to #2784589: Provide a method for module to specify that their toolbar items should appear in Edit mode

Problem/Motivation

Currently hook_toolbar is used to control toolbar item presence on particular pages. This hook is relatively under-powered and has a number of problem within it.

  1. The hook assumes that all items within it are global in scope.
    The hook is executed on each page to determine caching each time, so it is possible for it have different items per page, but in order to do this, a significant amount of logic has to be built into the hook itself for a given implementation. In the case where a menu item is available on canonical links of certain entity types given a set of criteria, the hook has no knowledge of the current route match nor any mechanism by which to couple routes to implementations within hook_toolbar. The net result is that menu systems like local tasks are much more robust and able to do things like properly respect route enhancers and other routing level objects that need to execute in order to inform the menu system of access/visibility of menu items.
  2. The hook is functionally building a render array.
    The expected return value of hook_toolbar is a render array. This seems problematic in and of itself but is especially jarring juxtaposed with D8's other apis. It feels like a real return to Drupal 6/7 style code. This is further problematic because each implementor of hook_toolbar has to manually apply things like AccessResult cacheability metadata to the render array rather than allowing the system to calculate that information appropriately based upon routing data.
  3. Toolbar modes aren't an actual thing.
    Reading a bit in the issue queue, and just actively using this system reveals a base-line assumption that there is such a thing as an "edit mode"
    of the toolbar, but this is not the case at all. Instead, the quickedit module's edit button has been hijacked by outside_in module and various menu items which don't have the appropriate data element on them are magically hidden when quickedit is activated. This is especially problematic imo because I actually understood what was happening at one point, but outside_in's approach conflated "edit mode" as a concept with "quickedit" as a functional thing. This is made more difficult because the menu items in the toolbar don't change so much as a subset of them are just exclusively displayed now.

Proposed resolution

  1. Introduce toolbar items as a top level menu api akin to local_tasks.
    We'll have to continue supporting hook_toolbar for BC purposes, but giving a new yaml file and plugin solution to building toolbar items would be a big boon. I'm pointing to local_tasks because they support a notion of parenting which allows us to programmatically calculate sub-routes and do things like execute access methods in order to determine visibility. This should remove the need to write raw render array output AND streamline the creation of new toolbar items.
  2. Determine if toolbar modes are something we want to actively support.
    I'm personally in favor of the idea of toolbar modes, but we continue to discuss them as though they're something we support, and looking at the code, they're clearly not. If we want toolbar modes, let's build such a feature.

Remaining tasks

  • Discuss
  • Patch
  • Iterate

User interface changes

  • This could introduce a toggle or even mode selector within the toolbar. TBD

API changes

  • Introduction of new top level menu api for building toolbar items instead of raw render arrays in a hook.
  • Will need to maintain BC

Comments

EclipseGc created an issue. See original summary.

Wim Leers’s picture

Component: outside_in.module » toolbar.module

AFAICT this belongs in the toolbar.module component.

I remember there being various issues about this problem space in the past. Unfortunately, the person who built most of this, Jesse Beach, no longer does Drupal.

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

idebr’s picture

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.