Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294902

Define contextual entity operations through annotation; remove the context property from hook_menu items

$
0
0

Problem/Motivation

MENU_LOCAL_TASK and MENU_DEFAULT_LOCAL_TASK were removed by #2004334: Change notice: Separate Tabs (MENU_LOCAL_TASK) from hook_menu(). This has left contextual links somewhat stranded on hook_menu items.

One of the goals of converting hook_menu items to routes is to eventually remove the menu_router table. The context property of a menu item is stored in the menu_router table. Therefore, we must move the definition of the context of a menu item before we can remove this table. This should be the last impediment to removing the menu_router table.

The composition of contextual links in D7 is cumbersome and tied tightly to the rendering layer. The declaration of standard links available for an entity was introduced in #1970360: Entities should define URI templates and standard links. We can extend this pattern to reduce the cumbersomeness declaring contextual links as well.

Proposed resolution

We already define links for an entity as a keyed hash. We could define the contextual links in annotation as a sub-set of these links.

/**
* Defines the node entity class.
*
* @EntityType(
*   links = {
*     "canonical" = "/node/{node} ",
*     "edit-form" = "/node/{node}/edit",
*     "version-history" = "/node/{node}/revisions"
*   },
*   contextual_links = [
*     "edit-form",
*     "delete-form"
*   ]
* )
*/

Each entity (e.g. nodes, blocks, views, menus, etc.) would define their own set of contextual links. These sets would then be aggregated (much as they are today) into the set of inks associated with a unit during rendering (e.g. a menu block that provides contextual links to configure the block and edit the menu). The current end-user experience would not change.

Much complexity in the aggregation of contextual links can be removed in this issue because we will not longer need to process contextual links in the rendering layer. We can do this well before rendering.

We may be able to extend this work to automatically generate routes from patterns defined for links on an entity in the same way that the REST module generates routes for HTTP methods against entities. The two systems are highly analogous. Such work need not be undertaken in this issue.

Remaining tasks

Propose an initial patch.

User interface changes

There shouldn't be any.

API changes

Contextual links will no longer be identified in hook_menu as the value of the context property on a task item.
Contextual links will be declared as annotations on entities.


Viewing all articles
Browse latest Browse all 294902

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>