Local task name expectation in getFeaturedPageActions is fragile

Created on 7 March 2025, 26 days ago

Problem/Motivation

In #3511416-3: Integrate with Drupal core's 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 was what stopped Experience Builder's Edit button to show right away).

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

navigation.module

Created by

πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @GΓ‘bor Hojtsy
  • πŸ‡­πŸ‡ΊHungary GΓ‘bor Hojtsy Hungary
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    Adjusted the summary to include "Top Bar" for easy reference.

    Changed Category to Bug report.

    Added steps to reproduce.

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON
  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON
  • πŸ‡¬πŸ‡§United Kingdom catch

    Code in question is this:

       if (preg_match($canonical_pattern, $current_route_name, $matches)) {
          $entity_type = $matches[1];
          $edit_route = "entity.$entity_type.edit_form";
          // For core entities, the local task name matches the route name. If
          // needed, we could iterate over the items and check the actual route.
          if (isset($page_actions['page_actions'][$edit_route]) && $page_actions['page_actions'][$edit_route]['#access']?->isAllowed()) {
            $featured_page_actions[$edit_route] = [
              'page_action' => $page_actions['page_actions'][$edit_route],
              'icon' => 'pencil',
            ];
          }
    
    

    So is the fix to resolve the 'if needed' comment and iterate over the items?

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    the 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?

  • πŸ‡¬πŸ‡§United Kingdom catch

    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?

    Yeah 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.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Yeah 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.

    I 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.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Even 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.

  • πŸ‡¨πŸ‡¦Canada m4olivei Grimsby, ON

    Discussed in Slack as well. Conversation there couldn't recall a concrete reason for making this issue blocking.

    Removing the Navigation stable blocker label.

Production build 0.71.5 2024