Problem/Motivation
In #3511416-3: Featured Edit task is not shown for Experience Builder pages in 11.2's experimental Navigation Top Bar I found that navigation top bar identifies the featured page action for editing based on expecting the local task name to be the same as the route name (and both being the edit_form route name for the entity). @wimleers pointed out that the local task name could very well be different despite this core convention, so it would be more robust to not expect the local task name to be the same:
this seems like a straight up bug in
PageActions::getFeaturedPageActions(), then. Local task (plugin) IDs have to be unique, but have no other naming requirements. That's why\Drupal\Core\Menu\LocalTaskManager::getLocalTasksForRoute()only look at the route name, not the (local task plugin) ID.
(This was what stopped Experience Builder's Edit button to show right away).
Steps to reproduce
This is a crude way to reproduce, we should probably get a test written to better prove it out. For purposes of understanding the issue here though, I found it helpful.
- Checkout the latest 11.x branch. Make the following modification to
core/modules/node/node.links.task.yml. Here we are adjust the id of nodes 'Edit' local task such that it does not line up with the route it corresponds to.
diff --git a/core/modules/node/node.links.task.yml b/core/modules/node/node.links.task.yml index 7da46bf961e..e92d0134813 100644 --- a/core/modules/node/node.links.task.yml +++ b/core/modules/node/node.links.task.yml @@ -2,7 +2,7 @@ entity.node.canonical: route_name: entity.node.canonical base_route: entity.node.canonical title: 'View' -entity.node.edit_form: +entity.node.edit: route_name: entity.node.edit_form base_route: entity.node.canonical title: Edit
- Install Drupal standard profile on the latest 11.x
- Enable
navigation_top_barusing drush (b/c hidden) - Create an article
- View the artcle
Expected result
The primary Edit button should appear in the Navigaton top bar on the right hand side next to the page actions menu.

Actual result
The primary Edit button does not show up at all.

Proposed resolution
Update the logic in \Drupal\navigation\Plugin\TopBarItem\PageActions::getFeaturedPageActions to not reley on the local task id to match the route name.
Remaining tasks
MR
Review
User interface changes
Edit featured page action for canonical routes appears more consistently.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | edit_button_shows_up.png | 20.42 KB | m4olivei |
| #4 | edit_button_sadness.png | 16.6 KB | m4olivei |
Issue fork drupal-3511612
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
gábor hojtsyComment #3
wim leersComment #4
m4oliveiAdjusted the summary to include "Top Bar" for easy reference.
Changed Category to Bug report.
Added steps to reproduce.
Comment #5
m4oliveiComment #6
m4oliveiComment #7
catchCode in question is this:
So is the fix to resolve the 'if needed' comment and iterate over the items?
Comment #8
berdirthe route name is just as much convention as the local task, it's probably more reliable than the local task as route names are typically generated while local tasks aren't yet.
Could go a step further and look for __entity_form in the route definition, but that's also an extra lookup.
Either way, doesn't really seem like a stable blocker to me? extending this to support more cases won't require API/structure changes or anything like that?
Comment #9
catchYeah I was also wondering this - if it's a 'normal' bug and the fix is self-contained (e.g. doesn't require adding some kind of declarative API) then it doesn't feel like a blocker.
Comment #10
berdirI was wondering about that.
We can have a self-contained improvement to cover more cases, but it's probably not perfect. I've seen some discussions about what and if there should be a primary action on views pages for example, specifically admin pages such as admin/content and admin/people and whether the action there should be add user or edit view. Neither will be covered by this. But add user would be possible through the local action system that we already have.
Comment #11
catchEven if we need a declarative API eventually, we could still add that post-stable I think, just would take longer for contrib to be able to rely on it.
Comment #12
m4oliveiDiscussed in Slack as well. Conversation there couldn't recall a concrete reason for making this issue blocking.
Removing the Navigation stable blocker label.
Comment #13
svendecabooterI'm not sure if this is the right place for this feature request, but I would propose to add an alter hook to the getFeaturedPageActions() method.
In my case, I want a custom entity to have another "featured action", rather than the edit form.
Currently I don't see a way to achieve this.
IMHO core should provide sane defaults, but allow the option for contrib / custom module to change the default behaviour.
EDIT:
Just noticed this is a "TopBarItem" plugin, so I achieved this with a custom plugin.
Comment #14
morbus iffI early adopted the navigation module so I could get rid of admin_menu (so: everything forthcoming is "my fault"), and 11.2's forced top bar and this issue is a blocker for me, usability-wise (forcing me to retrain dozens of people and rewrite documentation on where tab links went). Force removing the "Tabs" block is one thing, but force-adding an extra click is quite another. The current code seems to assume that only one local task is "important", and that importance is determined in one specific way ("name same as route", which this issue hopes to fix).
Overall: