add an entity Links handler, to provide menu links/tasks/actions for entity types

Created on 1 June 2018, over 6 years ago
Updated 19 July 2024, 4 months ago

Problem/Motivation

Providing a UI for an entity type involves a lot of boilerplate code.

In particular, three YML files have to be provided:

- MODULE.links.menu.yml
- MODULE.links.task.yml
- MODULE.links.action.yml

These contain repetitive boilerplate code, where furthermore it's very easy to make a mistake and match up the route names incorrectly.

Proposed resolution

Add a new handler type for entities, 'link_provider'. This defines menu, task, and action links for an entity type.

Provide two link provider handlers in the Entity component that follow the standard admin UI pattern (for example, as used by Media module's entity types):

- DefaultContentEntityLinkProvider
-- defines a local task link for the collection under admin/content, alongside the Content admin listing
-- defines a menu link for the collection as well, so it appears in the admin toolbar
-- defines the 'add new entity' action link on the collection page
-- defines a set of local tasks link for view/edit/delete for a single entity

- DefaultConfigEntityLinkProvider
-- defines a menu link for the collection under admin/structure
-- defines the edit form local task link, which allows Field UI to attach its own tasks for the case that this config entity is the bundle for a content entity.

Both of these link provider handler classes expect to find the route names created by core's route_provider classes.

Entity types that customize their route provider to change or add routes would need to use their own link_provider handler (or keep using hardcoded link plugins of course).

Note that contextual links aren't provided by these, because they're part of Core-core, and contextual links are in a core module.

Remaining tasks

- Get a review from one of the managers of the plugin system. YAML plugins are not discoverable in core/lib (unlike annotation-based plugins), and so the current patch declares the plugin derivatives that are in core/lib/Core/Entity in system module's YAML files. This approach needs framework manager review.

Follow-ons

Convert core's entity types to use these handlers. This is left as as follow-up, because changing an entity type to use a link provider handlers will cause the plugin IDs of the link plugins to change. It's not clear whether the BC policy on plugin IDs applies to menu plugins, and there is no policy or defined way on how to handle YAML plugin ID changes -- see #2922451: [policy no patch] Make it possible to mark plugins as deprecated β†’ .

User interface changes

None.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated 30 minutes ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Needs framework manager review

    It is used to alert the framework manager core committer(s) that an issue significantly impacts (or has the potential to impact) multiple subsystems or represents a significant change or addition in architecture or public APIs, and their signoff is needed (see the governance policy draft for more information). If an issue significantly impacts only one subsystem, use Needs subsystem maintainer review instead, and make sure the issue component is set to the correct subsystem.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Added a 10.1 branch and MR.

  • Status changed to Needs work almost 2 years ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    The branch is up to date AFAICT.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Looking into MR 3441 I see tests were added so removing that tag.

    Remaining tasks mention

    Get a review from one of the managers of the plugin system. YAML plugins are not discoverable in core/lib (unlike annotation-based plugins), and so the current patch declares the plugin derivatives that are in core/lib/Core/Entity in system module's YAML files. This approach needs framework manager review.

    So tagging for that.

    The 1 failure in the MR seems valid.

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

    Rebased branch 2976861-add-an-entity-Links-handler-to-provide-menu-linkstasksactions-for-entity-types for 9.5 and 2976861-10.1-add-an-entity-Links-handler-to-provide-menu-linkstasksactions-for-entity-types for 10.1.

  • πŸ‡­πŸ‡ΊHungary pasqualle πŸ‡­πŸ‡Ί Budapest

    I have a question about entity collection listing: Is there a guideline, policy or d.o issue about where the entity list should go in the admin menu?
    something like:
    - if you extend the ContentEntity class, then your entity listing should be under admin/content/my-entity-plural
    - if you extend the ConfigEntity class, then your entity listing should be under admin/structure/my-entity-plural

    Some of the examples where this "guideline" does not apply:
    Shortcuts (ContentEntity from core) listing is under /admin/config/user-interface/shortcut
    Taxonomy terms (ContentEntity from core) listing is under /admin/structure/taxonomy/manage/%vocabulary%/overview
    Image styles (ConfigEntity from core) listing is under admin/config/media/image-styles
    Workflows (ConfigEntity from core) listing is under admin/config/workflow/workflows
    Languages (ConfigEntity from core) listing is under admin/config/regional/language
    Entity Browsers (ConfigEntity from entity_browser module) listing is under admin/config/content/entity_browser
    Newsletters (ConfigEntity from simplenews module) listing is under /admin/config/services/simplenews
    QRCodes (ContentEntity from qrcode module) listing is under /admin/config/services/qrcode

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

    There isn't guidance AFAICT.

    There's a common pattern for content entity type/content entity type bundle pairs of admin/content and admin/structure.

    Beyond that, as you say, there's a lot of variance. But the base classes here are meant to cover the common case and can be extended for other cases.

  • πŸ‡¬πŸ‡§United Kingdom AaronMcHale Edinburgh, Scotland

    I have a question about entity collection listing: Is there a guideline, policy or d.o issue about where the entity list should go in the admin menu?

    While we were working on the effort to reorganise blocks in the admin UI, we were guided by structured content principles, and we applied these to the Drupal admin menu as follows:

    • Content: this is where you create individual items of content (whether that be nodes, blocks, media, etc).
    • Structure: this is where you build the structures that your content uses (aka bundles and fields), along with different representations of your structure (thinking Views here).
    • Appearance: this is where you decide what the look and feel of your site as a whole (aka selecting a theme, and hopefully in 10.2 the global block layout).

    There's a nice organisation there, from individual items up to the whole site.

    This isn't formally documented anywhere that I'm aware of (maybe it should be), but we will likely use this to help inform any future reorganisation efforts of the admin UI.

    In terms of how that relates to the question on this issue, it allows us to think about this a little more holistically. For collections of content entities, in general those probably fit best under Content; If it's a collection of config entities, those could live under Structure if they facilitate structured content (aka bundles and fields), but those could also live under Configuration if they are not related to structured content.

  • Pipeline finished with Failed
    4 months ago
    Total: 162s
    #226434
  • Pipeline finished with Failed
    4 months ago
    Total: 796s
    #226432
  • πŸ‡¬πŸ‡§United Kingdom joachim

    > For collections of content entities, in general those probably fit best under Content; If it's a collection of config entities, those could live under Structure if they facilitate structured content (aka bundles and fields), but those could also live under Configuration if they are not related to structured content.

    Are you suggesting we split DefaultConfigEntityLinksProvider into two classes,

    - one for config entities for structured content, under Admin > Structure
    - one for config entities that live under Admin > Configuration

    In which case, for Configuration config entities, we'd need an entity property to specify the base route.

  • Pipeline finished with Failed
    4 months ago
    Total: 487s
    #226470
  • Pipeline finished with Failed
    4 months ago
    Total: 165s
    #226523
  • Pipeline finished with Failed
    4 months ago
    Total: 159s
    #226839
  • Pipeline finished with Failed
    4 months ago
    Total: 154s
    #226884
  • Pipeline finished with Failed
    4 months ago
    Total: 170s
    #226951
  • πŸ‡¬πŸ‡§United Kingdom joachim

    I've decided not to wait for figuring out how to deprecate plugins.

    Instead, we can use alter hooks to ensure that plugin IDs are maintained for node and node_type links. We can remove those in due course. In fact, there is already this exact same handling in node module currently!

    A separate problem is that core/modules/views/tests/src/Kernel/TestViewsTest.php is failing on a recursive router rebuild, because of Views. The chain goes like this:

    - views data needs to know about routes
    - the router is built
    - MenuRouterRebuildSubscriber tells MenuLinkManager to rebuild() links
    - that calls our new EntityMenuLinkDeriver
    - BaseEntityLinksProvider checks routes for things

    I'm not sure why this circularity is only coming up in Views, and only in that kernel test. After all, I don't get an error when I go `drush cr` with this MR.

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

    Ok it looks like it IS Views that's somehow the problem, as if I add this kernel test on this branch, it passes:

      public function testRouteBuilderRebuild(): void {
        $this->container->get('router.builder')->rebuild();
    
        $this->assertTrue(TRUE);
      }
    
  • Pipeline finished with Failed
    4 months ago
    Total: 172s
    #228739
  • Pipeline finished with Failed
    4 months ago
    #228749
Production build 0.71.5 2024