Problem/Motivation

The following table summarises how to define dynamic items with the successors of hook_menu().

Type To create dynamic elements Docs
Route route_callbacks: entry in routing.yml that is a list of class names; HOWEVER if dependent on other routes, need to implement an event subscriber service (*.services.yml + custom class) with alterRoutes(). Docs
Menu link Implement hook_menu_link_defaults_alter().

#2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module proposes to add a solution to provide a 'fake' menu link in your *.menu_links.yml with a derivative key that points to a class implementing the actual dynamic menu items (similar to below). It also renames the alter hook to hook_menu_links_alter().

Docs
Local tasks Add a 'fake' local task element in your *.local_tasks.yml file with a derivative key that points to a class implementing the actual dynamic local tasks. Docs
Local actions Add a 'fake' local action element in your *.local_actions.yml file with a derivative key that points to a class implementing the actual dynamic local actions. Docs
Contextual links Add a 'fake' contextual link element in your *.contextual_links.yml file with a derivative key that points to a class implementing the actual dynamic links. Docs

Proposed resolution

Don't know.

Remaining tasks

Discuss.

User interface changes

None.

API changes

Maybe.

Comments

Gábor Hojtsy’s picture

Issue summary: View changes
dawehner’s picture

Regarding menu links: #225651 will also allow you to use derivatives ... maybe worth to mention

A rainbow then consists of 2 colors.

Gábor Hojtsy’s picture

Issue summary: View changes

@dawehner points out that #2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module unifies dynamic menu links uses the same patterns as for local tasks/contextual links/actions for derivatives.

Gábor Hojtsy’s picture

Title: Creating dynamic hook_menu() successor items is a rainbow of APIs » Creating dynamic hook_menu() successor items use different APIs
Issue summary: View changes
Related issues: +#2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module

@daweher: one more good reason to get the menu issue in :)

effulgentsia’s picture

Routes and Links are different. Is it so bad for them to have different patterns for creating dynamic ones? I agree that having the same pattern for the 4 link types is desirable, but just that much is a dupe of #2256521: [META] New plan, Phase 2: Implement menu links as plugins, including static admin links and views, and custom links with menu_link_content entity, all managed via menu_ui module, so then what becomes the goal of this issue?

Gábor Hojtsy’s picture

If that is the extent we want to unify them, then this can be marked a duplicate.

xjm’s picture

Issue tags: +beta deadline
Gábor Hojtsy’s picture