Part of to #2259445: Entity Resource unification, read that issue for more details.
Entity annotations should define link relationships by URI template, not route. We determined in Amsterdam that it's best to not make it temporary and just switch everything over at once.
API changes
Entity annotations allows to specify so called 'link templates'.
Before #2281645: Make entity annotations use link templates instead of route names they used to be keyed by operation with route names as values.
These route names had already the convention in core to be $entity_type.str_replace('-', '_', $operation)
, see following example:
* links = {
* "canonical" = "entity.node.canonical",
* "delete-form" = "entity.node.delete_form",
* "edit-form" = "entity.node.edit_form",
* "version-history" = "entity.node.version_history",
* }
After the change, the path is used, but the convention for the route names still exists.
* links = {
* "canonical" = "/node/{node}",
* "delete-form" = "/node/{node}/delete",
* "edit-form" = "node/{node}/edit",
* }
Beta phase evaluation
Issue category | Task because it does not fix any bugs |
---|---|
Issue priority | Major because of the reason outlined in #2259445: Entity Resource unification |
Prioritized changes | This is a prioritised change because the main goal of this issue was agreed at Amsterdam. |
Comment | File | Size | Author |
---|---|---|---|
#128 | interdiff.txt | 1.61 KB | dawehner |
#128 | 2281645-128.patch | 100.01 KB | dawehner |
#125 | interdiff.txt | 3.32 KB | dawehner |
#125 | 2281645-125.patch | 99.81 KB | dawehner |
#98 | 2281645-98.patch | 93.06 KB | dawehner |
Comments
Comment #1
dawehnerComment #2
tim.plunkettComment #4
tim.plunkettContentTranslationRouteSubscriber will have to work around this as well.
$entity_route = $collection->get($entity_type->getLinkTemplate('canonical'))
won't work anymore.Comment #5
dawehnerThank you tim, for pointing this out!
There are a couple of more places of which not all of them seem straightforward.
This issue feels more like research tbh.
Comment #7
Crell CreditAttribution: Crell commentedgetLinkTemplate() should return, well, the template. :-) What's it returning now if not that (presumably in a roundabout way via the routes)?
Comment #8
tim.plunketthttps://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
Comment #9
dawehnerHere is a bit more work ... You can work around most of the instances but let's be honest, using routes is actually better
in quite some places.
Here is an alternative approach we could discuss as well:
I really think that for most link templates using routes is actually way better. There are so many admin routes
which simply never makes sense to expose to rest. Here is a thought, why don't we keep the linkTemplates as route names but define a canonical path on top of it?
Comment #11
dawehnerThis time with the proper interdiff.
The node admin theme relies 100% on the route, so content translation has to deal with the route somehow.
Comment #12
Crell CreditAttribution: Crell commentedIt's not just REST. Many of those admin pages we want Drupal to auto-build for us from the annotations to make spinning up new entity types as easy as possible.
Comment #13
dawehnerComment #14
Crell CreditAttribution: Crell commentedI've so missed you, dawehner. :-)
The code looks good. Can we convert at least a few entity links back to uri templates to confirm everything is working? (Probably either comment or entity_test, as the other major content entities have issues already to rename their routes and we don't want to collide with those patches.)
Comment #15
dawehnerI tried to go with comment module first.
Comment #17
andypostWe should get rid of
entity_uri
first because it does not work nowComment #18
dawehnerWell, right, but this is another kinda orthogonal problem space.
Comment #19
dawehnerRewrote with using proper entity route names / paths if possible.
Comment #21
dawehnerSome progress ...
Note: this issue includes the menu and the views patch in order to not fail everywhere. It also fixes the action and contact module.
Comment #23
dawehnerUploading a new patch. This has not the views issue anymore applied.
Comment #25
dawehnerSome major problem at the moment: node for example has the field_ui_display_overview_node_type. Thinking about a proper solution.
The best strategy for now could be to avoid dealing with field_ui in this conversion.
Comment #26
dawehnerSome progress, no actual though.
Comment #28
dawehnerThis ensures that the usual field_ui form works, but especially together with config translation this is a mindfuck.
I doubt it is a perfect idea in the first place to not support custom route names in the link templates.
For those UI only routes it feels much more appreciate to have something like link templates but with routes.
Comment #30
dawehnerLet's see for now.
Comment #32
dawehnerWork ...
Comment #34
dawehnerSome more fixes. Still have no idea on the
DefaultConfigTest
Comment #36
BerdirWas this accidently re-added? I think we removed this when admin-form was changed to field_ui_base_route?
Comment #37
dawehnerSome work.
Comment #39
dawehnerLet's see, I would prefer something below 50 failures.
Comment #41
dawehnerStill issues with translation fields, other issues are fixed though.
Comment #43
dawehnerSome more work.
Comment #45
dawehnerMore fixes.
Comment #46
dawehnerComment #49
andypostSuppose we should extract field_ui routes conversion into separate issue to minimize a patch and focus on actual changes.
Overall changes are great, but route rename causes current test failure
no reason ;)
s/fieldui.//
space
consistency?
entity.{field_entity_type}. it's confusing when the param ends
Comment #50
andypostFollow-up issue is #2346883: Standardize field_ui entity route names
Comment #51
andypostmerged changes
fixed leftover route renames
filed new bug #2347053: "Field settings" local task from Field UI is missing
Comment #52
andypostproper patch
Comment #55
Crell CreditAttribution: Crell commentedRetitling per discussion at Drupalcon Amsterdam.
Comment #56
dawehnerLet's see where we are now.i
Comment #58
dawehnerSome more.
Comment #60
pwolanin CreditAttribution: pwolanin commentedSo, I don't really care how we define these things - but we shouldn't define the path in both the link template and the route independently.
If we put the paths back were, we need to derive the routes from them.
Comment #61
andypostExtracted a part of patch
Comment #62
dawehnerMeh, less problems.
Comment #64
dawehnerReapply after the URL issue.
Comment #66
dawehnerReroll.
Comment #68
andypostI think content translation routes needs separate issue too.
Comment #69
dawehnerAnother day another try.
Comment #71
dawehnerSome less failures.
Comment #73
dawehnerThere we go.
Comment #74
dawehnerLet's start with converting some common cases to paths. Does anyone has an opinion whether we should add paths there everywhere already or whether this can happen in some follow up?
The paths here aren't the hard to review part of the issue though to be honest.
Comment #75
dawehnerLet's unassign to make it clear that reviews would be welcomed!
Comment #76
jhodgdonFinally, a patch that passes the tests!
So I looked through the test and I'm very confused about a few things:
a) Do modules defining entities have to both declare the paths in their entity annotation and set up routes for them in the routing.yml files? Looks like the answer is yes...
b) It looks like although you've said the setLinkTemplate() method now is supposed to be given a path, the calls in the patch from content_translation and field_ui modules -- which changed in the patch -- are still using routes. This patch would be more convincing to me if the calls to these functions that are updated in this patch were actually converted to using paths, instead of just being changed from one route to another route. If they still need things to be routes, then ... can we even make this change?
c) I guess I'm confused about why we want to do this at all actually. Most of our URL generation stuff is being moved over to using routes, and right there in the top of the patch:
This code is a lot more complicated because of this change. Why exactly do we want to do this? The two-line issue summary is not illuminating...
d)
There are a few places like this in the patch where calls to setLinkTemplate() have been changed, but I didn't see changes in corresponding routing.yml files. As far as I can see, there is no book.remove route defined anywhere in Core, nor is book.remove a path... What's going on here, and how can this work -- is there just no test coverage that is exercising this path or link template call? [applies to several pieces of the patch]
e) There is no update to the explanations in the Entity topic about entity routing. This is in core/modules/system/entity.api.php in @defgroup entity_api.
Comment #77
Berdira) For now. The goal is to automate the generation of them using a new entity handler, that you can opt-in to.
See #2350503: Add route generation handlers for entities and #2259445: Entity Resource unification
b) The conversion to links is on progress I think and not done yet.
c) See parent meta issue.
Comment #78
jhodgdonI think that there were objections above about field UI and probably content translation that they needed routes. I'd really like to see that these still work without the routes in there...
Comment #79
dawehner@jhodgdon
Quick story: In order to autogenerate routes you need some paths, you should not start with routes as you easily get into circular dependencies. On top of that
link templates aren't a concept we invented to be with routes, they are originally paths, as the name says.
Yes sure, this is currently ongoing work ...
Comment #80
jhodgdonBut the field UI module needs to have routes, in order to make field UI admin tasks/tabs/etc. for the Manage Fields and Manage Display and Manage Forms pages, right? Those have to be set up with route names... which I think was brought up early in this issue or the meta.
Comment #81
andypost@dawehner I think we need separate issue for CT routes... maybe just add to #2346883: Standardize field_ui entity route names because both affected by field ui!
Comment #82
dawehnerLet's post quite an update.
Comment #84
dawehnerThis time it should install.
Comment #86
dawehnerIt could be green, reviews are always welcomed.
Comment #89
Crell CreditAttribution: Crell commentedSome minor issues. Overall there's not much here to object to. (I assume the fail is now because the patch needs a reroll.)
Existing issue, but can we standardize the array style on this line? (To new-style, presumably.)
Totally anal nitpick: One of these method implementations is using concatenation, the other interpolation. We should probably pick one. (I like interpolation, myself, but don't feel that strongly.)
Oopsies.
We're repeating this line a bunch of times. That suggests it could be internalized into a method on $entity_type.
Nitpick: Same format as the others. Or, make it a method.
This looks like the code to support the temporary dual options, da? If so, it needs a @todo.
Comment #90
dawehnerWell, whatever ...
This is mostly a reroll for now.
Comment #91
Crell CreditAttribution: Crell commentedWe should still address point 5, and either a todo for point 7 or a explain why we're going to leave it.
Comment #92
jhodgdonSo... My understanding of this issue is that the idea is that entities will no longer define routes in their annotations, and they will instead just have link templates. The 2-line issue summary says this too.
But ... it seems like they still have routes, but they are just less transparent than they used to be? Field UI, Content Translation, and Config Translation all require routes in order to work. So now they're magic instead of explicit in the entity definition? I mean, it looks like node.routing.yml doesn't have any changes in this patch, so the Node module still has to define the routes, but ... ???
Really we need an issue summary and a change notice so we can evaluate what this patch/issue is actually doing and what changes entity-providing modules will need to make in order for it to work.
Comment #93
dawehnerNote: this always have been about link template, which at some point switched from being paths to be route names. This issue
just forces the already existing naming scheme for entity routes on link templates.
Right, so you kinda misunderstood the purpose of this issue. This is about providing the base paths, so for example REST can use them.
Once you have both this issue and #2350503: Add route generation handlers for entities in place it will be possible to autogenerate basic routes.
Comment #94
jhodgdonThe issue summary on this issue is 3 lines. Perhaps a real summary would avoid this misunderstanding?
Comment #95
jhodgdonAlso will need a change notice, which will help explain the changes developers will need to do.
We also need to go through the flowchart on https://www.drupal.org/contribute/core/beta-changes and justify whether this issue even can be dealt with in 8.0.x, and add this to the issue summary. For this change, I think the justification has to be the "impact vs. disruption" defense.
Comment #96
dawehnerAdded a beta evaluation. I thought we decided to do this on Drupalcon Amsterdam.
Dear 19 people on this issue, feel free to review it.
Beta phase evaluation
improves the DX in the future. It is also major because it prevents REST module from potential bugs in the future.
is written down, it DOES NOT change the needed route names.
have to update their annotation
Comment #97
Crell CreditAttribution: Crell commentedCatch also specifically stated that this issue was OK to continue in Amsterdam. The disruption is, I agree, quite trivial.
The issue summary is small because it's just a part of the issue listed as the parent. There's little point in duplicating that summary here, and trying to carve out bits and pieces of it is, I believe, not a worthwhile use of time when the context of the parent issue is important anyway.
Comment #98
dawehnerAdressed point 5
Comment #99
Crell CreditAttribution: Crell commentedA static method? Why? It should be a method on EntityType.
Comment #100
dawehnerCome on, ... this is something just useful for FieldUI, given that it has to be done in a specific way.
Comment #101
dawehnerAdded a change record, so we can drop all the tags.
Comment #104
dawehnerRerolled.
Comment #106
dawehnerFor now just another reroll.
Comment #108
dawehnerSome bug fixes.
Comment #110
dawehnerSome less.
Comment #112
dawehnerSome less ...
Comment #114
dawehnerTake that!!
Comment #115
jhodgdonGreat, the tests finally passed!
A few nitpick/documentation comments on the patch:
a)
What does this "(temporary)" really mean? Very confusing, especially as it is in the @return, so how would I know what the function is returning? And in the setLinkTemplate for the $path argument too... I think the Core code is expecting paths now in most cases, and maybe is still expecting routes in some cases, but how is a user of the linkTemplates() function supposed to know which is being returned, and how is a user of the setLinkTemplate() function expected to know which is expected to be provided? The code as it is after this patch, I think, cannot really handle both in every case.
Really this documentation is unclear about when routes can be used and when paths are necessary. I think the only solution is to finish the patch and eliminate route names completely, unless you can be more specific in the docs, because this "temporary" is not clear at all.
b)
Extra blank line added in patch.
c)
See (a)... Why are these chunks of code still using/expecting/setting the link template to be a route instead of a path? If they cannot be made to work with paths, then this change should not, I think, be made at all. I've been trying to ask this question throughout the life of this issue and no one can answer the question of whether the translation and field UI modules can deal with them being paths instead of routes. I am still not convinced.
d) There is information in the Entity API topic (@defgroup entity in core/modules/system/entity.api.php) about how to define entities. I don't see this updated in the patch -- it is saying to put routes in the annotation currently. So that needs to be updated, and I think it also needs to explain the magic route names that you need to set up, because this will not be obvious to the novice entity type programmer.
e) I think that information about the magic route names you need to set up should also go into the draft change record. It looks like at least one of the core entities had a new route that had to be defined due to this change (it was using the "canonical" route for both the "canonical" link type and the "edit" link type and this is apparently not allowed any more. The change notice says nothing about this, but it is something some module developers would presumably need to change if Core needed to).
Comment #116
Wim LeersAt first, I was thoroughly confused by the first cited code block.
But then I saw the second and third cited code blocks, and the puzzle pieces suddenly fit together.
We're consciously choosing to violate DRY here, right?
What happens if the path defined in the route doesn't match that in the
links
annotation in the entity type definition?EDIT: read #2259445: Entity Resource unification. The IS there says:
So that's how we'll fix the DRY violation: we will add code that automatically generates all entity routes, i.e. for every link relationship. This will be done in #2350509: Implement auto-route generation for all core entities and convert all of the core entities.. But this is major and that is normal. Which means it's quite likely we'll be stuck with the DRY violation. That'll be a very confusing DX. Which makes me think we should bump #2350509: Implement auto-route generation for all core entities and convert all of the core entities. to major.
Like jhodgdon in a), I'm confused by this. Perhaps it's a remnant of what the IS currently says? (
)+1 to what jhodgdon says in c). I guess this is why it said "temporary". But is that still truly necessary, or does this just stem from early work from a long time ago? In other words: is it necessary for these to continue to use routes?
Still needs to be done here, or in a follow-up?
Nit: indentation problems.
Changing operation titles seems out of scopes?
Comment #117
dawehnerFeedback from @jhodgdon
Converted the other existing usecases. In general ... we will use the paths for really generic code like REST module, otherwise the path will not be used here, at least for now.
Updated ...
Just to be clear, this is not a notion introduce by this patch, it just enforces the policy existing since quite a long time. I hope you don't freak out because of that.
Feedback from @Wim Leers
Note to point 1: We just move the RY violation from the routes names to the route paths. Its mothing fundamentally new we introduce here.
Yes, we might be able to auto-generate some routes, but certainly not all,
Never understood that point though honestly, it just gave the patch a hard time.
Fixed
It is done right below it :)
OH that was probably caused by some of the crazy rebasing.
Comment #118
andypostno need in second line
It's not clear why field storage edit is bound to field config.
Suppose field_config entity suffix should not contain "_field" just "_edit_form" and "_delete_form"
used path looks strange
Comment #119
Wim LeersGreat point! Agreed.
Isn't it unsettling that the patch was green before this change?
We could add some validation in
setLinkTemplate()
, e.g. check if the first character is a slash, otherwise throw an exception?Don't these need a leading slash like the other link templates?
Comment #120
dawehnerWell yeah we could ... we indeed never used the VALUE of that link template, which is the reason why it passed.
Yeah we should.
Comment #121
dawehnerAdded an exception and expanded the unit test coverage for it.
Comment #123
dawehnerLet's see whether this fixes it all.
Comment #124
Wim LeersYay!
s/takes path/accept paths/
80 cols; could be fixed on commit.
80 cols.
Super nitpicky: s/entity type/entity type ID/
s/see/See/
80 cols.
RTBC because all nitpicks can easily be fixed on commit.
Comment #125
dawehnerFixed the nits.
Comment #126
Wim LeersThanks!
Comment #127
jhodgdonOne more minor nit, in EntityTypeInterface:
This needs an @throws, due to:
in EntityType right?
This is also garbled:
It now says
These go into the 'links' annotation, with the link type as the key, and the path of this link template.
Needs "... as the value".
Comment #128
dawehnerThank you, here is a fix for those points.
Finally we managed to got over the 100k patch size :)
Comment #129
Wim LeersAFAICT #128 addressed all concerns in #127 (good nitpicks btw!).
Comment #130
jhodgdonThanks!
Comment #131
chx CreditAttribution: chx commented*blink* can we remove the rest of the route system in a followup as well? Since we are not using route names here I am sure it can be done elsewhere. Progress at last.
Comment #132
alexpottCommitted 77725b6 and pushed to 8.0.x. Thanks!
I added the beta evaluation to the issue summary.
Comment #134
dawehneralexpott++
alexpott++
alexpott++
alexpott++
alexpott++
Comment #135
jbrown CreditAttribution: jbrown commentedThis seems broken:
$link_templates isn't being used even though it is being tested for.
I now get this error when using a contrib module with a custom entity type:
Comment #136
Berdir@jbrown: Your routes must name conform to entity.$entity_type.$link_template (with - replaced with _). This worked fine for me after renaming my routes accordingly. We should probably mention that in the change record.
If you still have a bug, please open a follow-up.
Comment #137
jbrown CreditAttribution: jbrown commentedOkay thanks!
But why are the link paths specified at all in the annotations if they are also defined in the routing file?
Comment #138
BerdirSee #2350509: Implement auto-route generation for all core entities and convert all of the core entities..
Comment #139
jbrown CreditAttribution: jbrown commentedThanks!
Comment #141
dpiUpdated change log regarding route names.