Part of #2259445: Entity Resource unification

Problem/Motivation

Let's make any API changes now for the parent issue so that it doesn't block beta.

Proposed resolution

In order to get the API changes taken care of up-front for the parent issue, we are going to rename all of the entity-related routes to match what they will be once they are auto-generated. That way, once we start auto-generating them we can remove the static ones or not and there's no affect on module developers.

Remaining tasks

Rename all entity HTML routes to match a common format.

The common format is: entity.$entityname.$relationship, where $entityname is the machine name of the entity and $relationship is the relationship as defined in the entity annotation, machine-name-ified. (Convert - to _).

For example, there are five routes defined for in Node's annotation right now: canonical, delete-form, edit-form, version-history, admin-form. Their route names should therefore be entity.node.canonical, entity.node.delete_form, entity.node.edit_form, entity.node.version_history, and entity.node.admin_form, respectively.

This requires a change to the entity annotation, the defined routes, and any generator calls to those routes.

The admin-form "link" is an odd case. It is not actually a proper link, and duplicates a link on NodeType. Instead, it should use the same route name as the node type's edit link and eventually be removed as part of #2309187: Fix double-link-entry between Entity and Entity Type classes.

User interface changes

None.

API changes

Many routes will have different names. Otherwise no change.

CommentFileSizeAuthor
#87 2278567-87.patch28.01 KBdawehner
#82 interdiff.txt1.34 KBkgoel
#82 standardize-entity-routes-2278567-82.patch28.01 KBkgoel
#80 interdiff.txt7.32 KBdawehner
#80 standardize-entity-routes-2278567-80.patch28.02 KBdawehner
#79 standardize-entity-routes-2278567-79.patch27.81 KBdawehner
#76 interdiff.txt1.34 KBkgoel
#76 standardize-entity-routes-2278567-76.patch28.89 KBkgoel
#74 standardize-entity-routes-2278567-74.patch28.88 KBkgoel
#74 interdiff.txt6.55 KBkgoel
#72 interdiff.txt2.01 KBkgoel
#72 standardize-entity-routes-2278567-72.patch28.78 KBkgoel
#70 interdiff.txt6.8 KBkgoel
#70 standardize-entity-routes-2278567-70.patch28.77 KBkgoel
#68 interdiff.txt2.01 KBkgoel
#68 standardize-entity-routes-2278567-68.patch22.5 KBkgoel
#60 standardize-entity-routes-2278567-60.patch22.4 KBkgoel
#54 standardize-entity-routes-2278567-54.patch22.57 KBkgoel
#51 standardize-entity-routes-2278567-51.patch22.56 KBkgoel
#50 standardize-entity-routes-2278567-50.patch21.88 KBkgoel
#38 standardize-entity-routes-2278567-38.patch22.06 KBazinck
#35 standardize-entity-routes-2278567-35.patch22.05 KBazinck
#32 standardize-entity-routes-2278567-32.patch22.44 KBazinck
#27 standardize-entity-routes-2278567-27.patch22.49 KBazinck
#23 standardize-entity-routes-2278567-23.patch22.97 KBazinck
#22 standardize-entity-routes-2278567-22.patch24.17 KBazinck
#21 standardize-entity-routes-2278567-21.patch24.63 KBazinck
#17 standardize-entity-routes-2278567-17.patch23.5 KBkgoel
#15 standardize-entity-routes-2278567-12.patch11.26 KBkgoel
#13 standardize-entity-routes-2278567-11.patch10.39 KBkgoel
#11 standardize-entity-routes-2278567-10.patch9.95 KBkgoel
#9 standardize-entity-routes-2278567-9.patch10.07 KBkgoel
#7 standardize-entity-routes-2278567-7.patch9.48 KBkgoel
#4 standardize-entity-routes-2278567-4.patch21.11 KBkgoel
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett’s picture

What about entity types that don't happen to match their module name?
Our current policy is to namespace routes by their module name.

kgoel’s picture

Assigned: Unassigned » kgoel
Crell’s picture

Tim: I guess this would be an exception. I don't think node.node.page is a particularly friendly route name.

kgoel’s picture

Status: Active » Needs review
FileSize
21.11 KB

Initial patch ...

Status: Needs review » Needs work

The last submitted patch, 4: standardize-entity-routes-2278567-4.patch, failed testing.

kgoel’s picture

looking at the fails. I am going to remove canonical route name and submit patch again.

kgoel’s picture

Status: Needs work » Needs review
FileSize
9.48 KB

Status: Needs review » Needs work

The last submitted patch, 7: standardize-entity-routes-2278567-7.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
10.07 KB

Status: Needs review » Needs work

The last submitted patch, 9: standardize-entity-routes-2278567-9.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
9.95 KB

Status: Needs review » Needs work

The last submitted patch, 11: standardize-entity-routes-2278567-10.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
10.39 KB

Status: Needs review » Needs work

The last submitted patch, 13: standardize-entity-routes-2278567-11.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
11.26 KB
kgoel’s picture

Since last patch passed for delete-form, edit-form, version-history, admin-form route name change. I am going to work on canonical route name.

kgoel’s picture

Status: Needs review » Needs work

The last submitted patch, 17: standardize-entity-routes-2278567-17.patch, failed testing.

kgoel’s picture

kgoel’s picture

Title: Standardize entity route names by relationship » Standardize node route names by relationship
azinck’s picture

Status: Needs work » Needs review
FileSize
24.63 KB

Rerolled

azinck’s picture

Fix the _entity_access values.

azinck’s picture

oops -- removed debugging cruft.

The last submitted patch, 21: standardize-entity-routes-2278567-21.patch, failed testing.

The last submitted patch, 22: standardize-entity-routes-2278567-22.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 23: standardize-entity-routes-2278567-23.patch, failed testing.

azinck’s picture

Status: Needs work » Needs review
FileSize
22.49 KB

Missed fixing one _entity_access value.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

It all looks pretty simple to me. Straight renames. Thanks team!

azinck’s picture

Status: Reviewed & tested by the community » Needs work

Might want to put the brakes on this for now as the patch only covers nodes and not all entities. I believe kgoel was going to finish up with the other entities.

tim.plunkett’s picture

Status: Needs work » Reviewed & tested by the community

In #19/#20 this was turned into a subissue of #2285413: [Meta] Standardize entity route names and renamed to be just about nodes. You are correct that it was originally a much larger scope.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: standardize-entity-routes-2278567-27.patch, failed testing.

azinck’s picture

Status: Needs work » Needs review
FileSize
22.44 KB

Rerolled to track HEAD.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

And back.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 32: standardize-entity-routes-2278567-32.patch, failed testing.

azinck’s picture

Status: Needs work » Needs review
FileSize
22.05 KB

Rerolled

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Before something else breaks this, please... :-)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 35: standardize-entity-routes-2278567-35.patch, failed testing.

azinck’s picture

Status: Needs work » Needs review
FileSize
22.06 KB

Rerolled

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Sweet Jebus... Thanks, azinck!

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review

What about entity types that don't happen to match their module name?

I think that could use a bit more discussion. What about prefixing with entity? e.g., entity.node.page?

Crell’s picture

Status: Needs review » Reviewed & tested by the community

That just makes the route names unnecessarily long, IMO.

(Sorry if I sound curt; but this is part of a beta-target line of work so I really really don't want to bikeshed it, especially when it's already as fragile as it is and keeps breaking.)

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review

I appreciate the desire to get the route names standardized before beta. Especially since this is just for nodes, and we have many more entity types to go. But, it's counterproductive to get this in and then realize later that the naming convention is problematic and needs to be changed. So let's get it right the first time.

The problems with using a short ENTITY_TYPE.RELATIONSHIP pattern are:

  1. We have in core, several entity types not namespaced to their module. For example, date_format. So, if there were a contrib module named date_format, it would need to make sure to not define any routes that happen to have the same name as a link relation.
  2. Even if you argue that the above is a separate bug, and that we should either rename those entity types or squat their project names on d.o. to prevent a contrib module from grabbing it, you also have the situation that contrib can add more link relations. For example, in HEAD, user module defines a user.account_settings route that is not an entity route. What happens when a contrib module decides it wants to add an "account-settings" link relation for the user entity type?

By the way, the routes that REST module generates for entity types follows the pattern of either rest.entity.ENTITY_TYPE.HTTP_METHOD or rest.entity.ENTITY_TYPE.HTTP_METHOD.FORMAT. So there's already precedent for using the entity prefix.

Crell’s picture

effulgentsia: OK, let me put it another way.

We're talking about going from "node_view" to "entity.node.page". That's around a 40% longer name. To me, well, I don't care. However, we're talking about the project that has method and function names with a single letter to save typing, and high-influence developers that have objected, repeatedly, to "I have to type that much instead of one short [if completely non-obvious] function name? That's bad DX!" I take it as a given that we're going to emphasize brevity as if it were always a proxy for good DX (it's not, but that doesn't stop Drupal from treating it as such), which means a longer route name is going to be seen, by some at least, as a DX regression.

And I have nowhere near enough karma left to waste any of it on that fight. So if you're willing to handle any flack that comes from a 40% increase in the name length of the most common routes for module developers to write, fine. But I am not willing to burn any more karma on it.

(If I sound exasperated, that's because I am. The beta-sensitive issues remaining in the WSCCI/SCOTCH realm are moving at the pace of a narcoleptic snail, with even minor refactorings sitting in the queue for a month, and this particular line of work is about fixing a regression I've been trying to get fixed for the past 7 months and have had to fight tooth and nail on. Bikeshedding the name of a string on an issue that's already RTBC ranks high on the "reasons to give up and become a plumber" list these days.)

alexpott’s picture

Asked to comment in a wscii meeting. I think we should prefix with entity. too. @sun +1'd in IRC too.

kgoel’s picture

working on prefixing with entity

effulgentsia’s picture

Sorry to be a pain, but also, what is the rationale for using "page" instead of "canonical"? TBH, I prefer entity.node.canonical to entity.node.page. @alexpott and others: thoughts?

EDIT: I realize that "canonical" is longer than "page", but it has a meaning that is more precise, which is why I like it.

Crell’s picture

Issue summary: View changes
Crell’s picture

effulgentsia: We just discussed that in channel. You should be there. :-)

The routes we're talking about here are specifically HTML routes. The canonical URI can be used for all sorts of things, including HTML, JSON, SVG, PDF, or whatever else. REST module would generate the non-HTML routes if we go the automated approach with them.

However, HTML should not "squat" the main route name. The HTML version of an entity is a page. But not all versions of a canonical entity are HTML.

effulgentsia’s picture

"canonical" isn't the only link relationship that can apply to non-HTML. "version-history" and many others can as well. We will need some way for non-HTML routes to occupy a different namespace than HTML routes. Currently, that way is that in HEAD, non-HTML routes for entity operations are prefixed with "rest.entity" while this issue, as of #44, is proposing to prefix HTML routes with "entity". If we're unhappy with "entity" prefix = HTML and "rest.entity" prefix = non-HTML, that's a separate thing for us to figure out, and special-casing "canonical" is neither necessary nor sufficient for addressing that.

kgoel’s picture

kgoel’s picture

Forgot to add one file

The last submitted patch, 50: standardize-entity-routes-2278567-50.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 51: standardize-entity-routes-2278567-51.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
22.57 KB
Crell’s picture

Status: Needs review » Reviewed & tested by the community

Quick, before someone else commits something! :-) Thanks.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  *   see the node.view route in node.routing.yml for an example, and see

Needs fixing in core/modules/system/core.api.php

+++ b/core/modules/node/src/Entity/Node.php
@@ -52,11 +52,11 @@
- *     "canonical" = "node.view",
- *     "delete-form" = "node.delete_confirm",
- *     "edit-form" = "node.page_edit",
- *     "version-history" = "node.revision_overview",
- *     "admin-form" = "node.type_edit"
+ *     "canonical" = "entity.node.page",
+ *     "delete-form" = "entity.node.delete_form",
+ *     "edit-form" = "entity.node.edit_form",
+ *     "version-history" = "entity.node.version_history",
+ *     "admin-form" = "entity.node.admin_form"

I agree with @effulgentsia if we are standardising route names to entity.TYPE.RELATION. It's pointless to make an exception to that standard by saying "except when RELATION=canonical, then make it entity.TYPE.page".

effulgentsia’s picture

To clarify my position from #49: I agree with #48's requirement that html and non-html need to have different route names. And I think HEAD's approach of prefixing REST-module defined non-HTML routes with "rest." is an acceptable way of achieving that. If we want to change that, however, we need to change it to something that doesn't rely on coming up with format-specific variants of link relation names. Therefore, what makes entity.node.canonical acceptable as an html-only route name isn't that "canonical" as a concept is limited to HTML, but that the entire entity.TYPE.RELATION route naming pattern is something we're limiting to HTML, and that non-HTML routes will need a different pattern entirely (e.g., prefixed with rest.), so that we can have non-HTML routes for version-history and other non-canonical relations just as easily and consistently as for canonical.

Crell’s picture

Issue summary: View changes

We discussed this in today's WSCCI meeting. catch pointed out that in most cases you should be generating an entity URL with $entity->url() anyway, not the route name. So... meh. canonical it is. Updated the summary. kgoel, 6th time's the charm, I hope?

kgoel’s picture

Sure, I will work on this later today.

kgoel’s picture

Status: Needs work » Needs review
FileSize
22.4 KB
dawehner’s picture

Issue tags: +Needs change notification, +Needs change record updates, +Needs change record

I guess the change record work has to be done.

+++ b/core/modules/content_translation/tests/src/Menu/ContentTranslationLocalTasksTest.php
@@ -53,19 +53,19 @@ public function testBlockAdminDisplay($route, $expected) {
-        'node.revision_overview',
...
+        'entity.node.version_history',

tbh. this is a bit odd given that the feature on entities is called revisions not version_history, but well this is how it is,
given that the link template has that key.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Change record added for all of these changes: https://www.drupal.org/node/2306387

Thanks, kgoel!

bojanz’s picture

Previously we defined node's admin-form to be the node_type edit route:

*     "admin-form" = "node.type_edit"

That made sense.

Now we've reversed that, node defines an admin_form route that performs node type editing (?!), specifies that as the admin-form link,
and the node type's edit-form now points to the entity.node.admin_form route:

- *     "edit-form" = "node.type_edit",
+ *     "edit-form" = "entity.node.admin_form",

What's the reasoning for this reversal? I find it very confusing.

Crell’s picture

The link relationship was already called admin-form, so by the standard here (which has already been bikeshedded to death) that would be entity.$type.admin_form. If we wanted a different auto-route then we'd need a different link name, and renaming the link is out of scope for this thread.

alexpott’s picture

+++ b/core/modules/node/src/Entity/Node.php
@@ -51,11 +51,11 @@
- *     "admin-form" = "node.type_edit"
...
+ *     "admin-form" = "entity.node.admin_form"

+++ b/core/modules/node/src/Entity/NodeType.php
@@ -36,7 +36,7 @@
- *     "edit-form" = "node.type_edit",
+ *     "edit-form" = "entity.node.admin_form",

I'm confused by this too. We're dealing with node type entities here. Why is this not entity.node_type.edit_form. And therefore programmatically - node's admin form is the edit form for its bundle entity type.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Agreed with #65, also seems odd to me.

Crell’s picture

Status: Needs review » Needs work
Related issues: +#2309187: Fix double-link-entry between Entity and Entity Type classes

Discussed this in today's WSCCI meeting.

The problem is that, currently, Node has a link of admin-form and NodeType has a link of edit-form, both of which point to the same place. That means the auto-generation logic is going to get confused, and at best we'll have 2 routes with the same pattern. (For some worst definition of best.) To make it more interesting, not all Entities have two classes: Only those that are Bundleable.

Temporary solution, as suggested by Alex:

* ALSO convert NodeType in this issue. (And similarly in other content entity conversion issues.)
* For now, Node admin-form should point to NodeType's route name (which would then be entity.node_type.edit_form).
* Sort out the double-entry problem in a follow up issue: #2309187: Fix double-link-entry between Entity and Entity Type classes

This will also unblock, at least for now, the other issues in this family.

kgoel’s picture

Status: Needs work » Needs review
FileSize
22.5 KB
2.01 KB

Status: Needs review » Needs work

The last submitted patch, 68: standardize-entity-routes-2278567-68.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
28.77 KB
6.8 KB

missed couple route name in previous patch

Status: Needs review » Needs work

The last submitted patch, 70: standardize-entity-routes-2278567-70.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
28.78 KB
2.01 KB
Crell’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/src/Entity/NodeType.php
@@ -36,7 +36,7 @@
  *   links = {
  *     "add-form" = "node.add",
- *     "edit-form" = "node.type_edit",
+ *     "edit-form" = "entity.node_type.edit_form",
  *     "delete-form" = "node.type_delete_confirm"

I believe the idea was to go ahead and convert add-form and delete-form here as well for completeness. Let's do that.

Other than that, this looks fine.

kgoel’s picture

Status: Needs work » Needs review
FileSize
6.55 KB
28.88 KB

Status: Needs review » Needs work

The last submitted patch, 74: standardize-entity-routes-2278567-74.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
28.89 KB
1.34 KB

Status: Needs review » Needs work

The last submitted patch, 76: standardize-entity-routes-2278567-76.patch, failed testing.

Crell’s picture

Issue summary: View changes
dawehner’s picture

Just a reroll, more later.

dawehner’s picture

Status: Needs work » Needs review
FileSize
28.02 KB
7.32 KB

There seemed to be quite some misunderstanding ...

Status: Needs review » Needs work

The last submitted patch, 80: standardize-entity-routes-2278567-80.patch, failed testing.

kgoel’s picture

Status: Needs work » Needs review
FileSize
28.01 KB
1.34 KB
Crell’s picture

Status: Needs review » Reviewed & tested by the community

huzzah!

The last submitted patch, 79: standardize-entity-routes-2278567-79.patch, failed testing.

dawehner’s picture

Issue tags: +Drupalaton 2014

meh.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll

git ac https://www.drupal.org/files/issues/standardize-entity-routes-2278567-82.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 28682  100 28682    0     0  64249      0 --:--:-- --:--:-- --:--:--  318k
error: patch failed: core/modules/book/src/Form/BookOutlineForm.php:103
error: core/modules/book/src/Form/BookOutlineForm.php: patch does not apply
dawehner’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
28.01 KB

Meh

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed cd8986c and pushed to 8.0.x. Thanks!

diff --git a/core/lib/Drupal/Core/Form/FormSubmitterInterface.php b/core/lib/Drupal/Core/Form/FormSubmitterInterface.php
index 15ce4d2..af9b3db 100644
--- a/core/lib/Drupal/Core/Form/FormSubmitterInterface.php
+++ b/core/lib/Drupal/Core/Form/FormSubmitterInterface.php
@@ -59,7 +59,7 @@ public function executeSubmitHandlers(&$form, FormStateInterface &$form_state);
    * @endcode
    * And here is an example of how to redirect to 'node/123?foo=bar#baz':
    * @code
-   * $form_state->setRedirect('node.view',
+   * $form_state->setRedirect('entity.node.canonical',
    *   array('node' => 123),
    *   array(
    *     'query' => array(
diff --git a/core/modules/menu_link_content/src/MenuLinkContentInterface.php b/core/modules/menu_link_content/src/MenuLinkContentInterface.php
index 1f56715..a5d0aca 100644
--- a/core/modules/menu_link_content/src/MenuLinkContentInterface.php
+++ b/core/modules/menu_link_content/src/MenuLinkContentInterface.php
@@ -48,8 +48,8 @@ public function getRouteParameters();
    *
    * @param array $route_parameters
    *   The route parameters, usually derived from the path entered by the
-   *   administrator. For example, for a link to a node with route 'node.view'
-   *   the route needs the node ID as a parameter:
+   *   administrator. For example, for a link to a node with route
+   *   'entity.node.canonical' the route needs the node ID as a parameter:
    *   @code
    *     array('node' => 2)
    *   @endcode
diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php
index 57a2e24..3d52bbd 100644
--- a/core/modules/system/system.api.php
+++ b/core/modules/system/system.api.php
@@ -411,9 +411,10 @@ function hook_page_build(&$page) {
  *   patten is the route name followed by a dot and a unique suffix. For
  *   example, an additional logout link might have a machine name of
  *   user.logout.navigation, and default links provided to edit the article and
- *   page content types could use machine names node.type_edit.article and
- *   node.type_edit.page. Since the machine name may be arbitrary, you should
- *   never write code that assumes it is identical to the route name.
+ *   page content types could use machine names
+ *   entity.node_type.edit_form.article and entity.node_type.edit_form.page.
+ *   Since the machine name may be arbitrary, you should never write code that
+ *   assumes it is identical to the route name.
  *
  *   The value corresponding to each machine name key is an associative array
  *   that may contain the following key-value pairs:

Fixed the above during commit.

  • alexpott committed cd8986c on 8.0.x
    Issue #2278567 by kgoel, azinck, dawehner | Crell: Standardize node...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

xjm’s picture

Issue tags: -Needs change notification