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.
Comment | File | Size | Author |
---|---|---|---|
#87 | 2278567-87.patch | 28.01 KB | dawehner |
#82 | interdiff.txt | 1.34 KB | kgoel |
#82 | standardize-entity-routes-2278567-82.patch | 28.01 KB | kgoel |
#80 | interdiff.txt | 7.32 KB | dawehner |
#80 | standardize-entity-routes-2278567-80.patch | 28.02 KB | dawehner |
Comments
Comment #1
tim.plunkettWhat about entity types that don't happen to match their module name?
Our current policy is to namespace routes by their module name.
Comment #2
kgoel CreditAttribution: kgoel commentedComment #3
Crell CreditAttribution: Crell commentedTim: I guess this would be an exception. I don't think node.node.page is a particularly friendly route name.
Comment #4
kgoel CreditAttribution: kgoel commentedInitial patch ...
Comment #6
kgoel CreditAttribution: kgoel commentedlooking at the fails. I am going to remove canonical route name and submit patch again.
Comment #7
kgoel CreditAttribution: kgoel commentedComment #9
kgoel CreditAttribution: kgoel commentedComment #11
kgoel CreditAttribution: kgoel commentedComment #13
kgoel CreditAttribution: kgoel commentedComment #15
kgoel CreditAttribution: kgoel commentedComment #16
kgoel CreditAttribution: kgoel commentedSince last patch passed for delete-form, edit-form, version-history, admin-form route name change. I am going to work on canonical route name.
Comment #17
kgoel CreditAttribution: kgoel commentedComment #19
kgoel CreditAttribution: kgoel commentedComment #20
kgoel CreditAttribution: kgoel commentedComment #21
azinck CreditAttribution: azinck commentedRerolled
Comment #22
azinck CreditAttribution: azinck commentedFix the _entity_access values.
Comment #23
azinck CreditAttribution: azinck commentedoops -- removed debugging cruft.
Comment #27
azinck CreditAttribution: azinck commentedMissed fixing one _entity_access value.
Comment #28
Crell CreditAttribution: Crell commentedIt all looks pretty simple to me. Straight renames. Thanks team!
Comment #29
azinck CreditAttribution: azinck commentedMight 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.
Comment #30
tim.plunkettIn #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.
Comment #32
azinck CreditAttribution: azinck commentedRerolled to track HEAD.
Comment #33
Crell CreditAttribution: Crell commentedAnd back.
Comment #35
azinck CreditAttribution: azinck commentedRerolled
Comment #36
Crell CreditAttribution: Crell commentedBefore something else breaks this, please... :-)
Comment #38
azinck CreditAttribution: azinck commentedRerolled
Comment #39
Crell CreditAttribution: Crell commentedSweet Jebus... Thanks, azinck!
Comment #40
effulgentsia CreditAttribution: effulgentsia commentedI think that could use a bit more discussion. What about prefixing with
entity
? e.g.,entity.node.page
?Comment #41
Crell CreditAttribution: Crell commentedThat 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.)
Comment #42
effulgentsia CreditAttribution: effulgentsia commentedI 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: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.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
orrest.entity.ENTITY_TYPE.HTTP_METHOD.FORMAT
. So there's already precedent for using theentity
prefix.Comment #43
Crell CreditAttribution: Crell commentedeffulgentsia: 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.)
Comment #44
alexpottAsked to comment in a wscii meeting. I think we should prefix with
entity.
too. @sun +1'd in IRC too.Comment #45
kgoel CreditAttribution: kgoel commentedworking on prefixing with entity
Comment #46
effulgentsia CreditAttribution: effulgentsia commentedSorry to be a pain, but also, what is the rationale for using "page" instead of "canonical"? TBH, I prefer
entity.node.canonical
toentity.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.
Comment #47
Crell CreditAttribution: Crell commentedComment #48
Crell CreditAttribution: Crell commentedeffulgentsia: 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.
Comment #49
effulgentsia CreditAttribution: effulgentsia commented"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.
Comment #50
kgoel CreditAttribution: kgoel commentedComment #51
kgoel CreditAttribution: kgoel commentedForgot to add one file
Comment #54
kgoel CreditAttribution: kgoel commentedComment #55
Crell CreditAttribution: Crell commentedQuick, before someone else commits something! :-) Thanks.
Comment #56
alexpottNeeds fixing in core/modules/system/core.api.php
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".
Comment #57
effulgentsia CreditAttribution: effulgentsia commentedTo 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 entireentity.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 withrest.
), so that we can have non-HTML routes forversion-history
and other non-canonical relations just as easily and consistently as forcanonical
.Comment #58
Crell CreditAttribution: Crell commentedWe 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?
Comment #59
kgoel CreditAttribution: kgoel commentedSure, I will work on this later today.
Comment #60
kgoel CreditAttribution: kgoel commentedComment #61
dawehnerI guess the change record work has to be done.
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.
Comment #62
Crell CreditAttribution: Crell commentedChange record added for all of these changes: https://www.drupal.org/node/2306387
Thanks, kgoel!
Comment #63
bojanz CreditAttribution: bojanz commentedPreviously we defined node's admin-form to be the node_type edit route:
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:
What's the reasoning for this reversal? I find it very confusing.
Comment #64
Crell CreditAttribution: Crell commentedThe 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.
Comment #65
alexpottI'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.
Comment #66
catchAgreed with #65, also seems odd to me.
Comment #67
Crell CreditAttribution: Crell commentedDiscussed 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.
Comment #68
kgoel CreditAttribution: kgoel commentedComment #70
kgoel CreditAttribution: kgoel commentedmissed couple route name in previous patch
Comment #72
kgoel CreditAttribution: kgoel commentedComment #73
Crell CreditAttribution: Crell commentedI 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.
Comment #74
kgoel CreditAttribution: kgoel commentedComment #76
kgoel CreditAttribution: kgoel commentedComment #78
Crell CreditAttribution: Crell commentedComment #79
dawehnerJust a reroll, more later.
Comment #80
dawehnerThere seemed to be quite some misunderstanding ...
Comment #82
kgoel CreditAttribution: kgoel commentedComment #83
Crell CreditAttribution: Crell commentedhuzzah!
Comment #85
dawehnermeh.
Comment #86
alexpottNeeds a reroll
Comment #87
dawehnerMeh
Comment #88
alexpottCommitted cd8986c and pushed to 8.0.x. Thanks!
Fixed the above during commit.
Comment #91
xjm