Updated: Comment #N
Problem/Motivation
Entity type annotations use a path based "links template" for the Entity::uri() method.
This is problematic because it means the paths are hardcoded in various parts of core, which will break when someone tries to alter a route's path.
This is part of a larger effort to only have paths defined in code in the *.routing.yml files or in a RouteSubscriber class.
Proposed resolution
Instead of specifying paths with placeholders like /node/{node}
, change the entity type links to hold route names like node.view
Remaining tasks
N/A
User interface changes
N/A
API changes
Entity type links are now route names.
Comment | File | Size | Author |
---|---|---|---|
#29 | interdiff.txt | 1.53 KB | tim.plunkett |
#29 | route-2133469-29.patch | 51.13 KB | tim.plunkett |
Comments
Comment #1
tim.plunkettComment #2
tim.plunkettWhoops, missed the hook_entity_info() ones.
Comment #3
tim.plunkettAnd the interdiff
Comment #5
tim.plunkettcontent_translation_entity_info_alter is still just appending /translations to the canonincal path.
In #1810350: Remove menu_* entity keys and replace them with entity links it was moved out of ContentTranslationRouteSubscriber, but that's almost worse...
I think I fixed the other cases.
Comment #6
damiankloip CreditAttribution: damiankloip commentedWhat's the change to the hal normalizer base test class about?
Comment #7
tim.plunkettWell I could have just changed NormalizeTest, DenormalizeTest was fine, but DUTB cannot handle routes properly AFAIK. I had to make the same change to FieldRdfaTestBase
Comment #9
damiankloip CreditAttribution: damiankloip commentedHmm, can't we just revert those changes to WebTestBase and add the router schema to the DUTB tests? I think that should work, let's try.
Interdiff includes reverting changes in those tests from the last patch and the changes needed.
EDIT:
For ease, this is all that I added to those tests after the code reverts.
Comment #10
Gábor HojtsyGreat patch!
Sounds like this would need to be fixed in this patch too? I believe the content translation module has derivative routes based on
entity routes, so this can be placed herethese. The routes are 'content_translation.translation_overview_' . $entity_type.It is true they are created based on this path provided here, but I think the path automation can just as well be moved to the route subscriber, those needing to alter that can alter the routes. AFAIS that should be very rare. That means this can go away from the info hook.
Comment #11
damiankloip CreditAttribution: damiankloip commentedCould we do something like this? Genuine question.
Comment #13
tim.plunkettThe config_test fail was because the test assumes there is a valid translation permission when there is not.
The rest was just cleaning up the places that check for these link templates.
Comment #15
tim.plunkettThe PHPUnit tests weren't updated.
To do so, I needed to move content_translation_supported() to a service.
Comment #17
tim.plunkettWe need to also check the collections being processed, not just the pre-existing one.
Comment #18
Gábor HojtsyThe uri() method counterpart is now at #2134871: Entities should provide route and route parameter methods (instead of uri()?).
Comment #19
tim.plunkettNow that we have a passing patch, I went back through and cleaned up some.
There are changes to content_translation that ideally wouldn't be included here, but they could not happen without this issue, and it is necessary for them to be included here. Sorry for the seeming scope-creep.
Comment #20
tim.plunkettd.o ate my patches and tags
Comment #21
dawehnerThe documentation of EntityType.$links has to be changed as well.
<3
Wait: we do remove access_callback but keep it above? I would like to understand that.
What is the reason to make an event subscriber have a different priority? The priority of it will be handled in the actual getSubscribers method anyway.
... this should be @entity.manager
What is the responsibility of this class?
I wonder myself about the usecase to specify the $info manually. I haven't looked core though, yet.
I really really love this line!
What is the reason for this change? Doesn't this causes a big slow down for the test?
Comment #22
tim.plunkettAddressed the other points:
3) Left access_callback in for this in \Drupal\content_translation\Access\ContentTranslationOverviewAccess
4) I can remove this, but @damiankloip added it, and I'm not sure what might break.
7) I'm removing this, its too confusing to be useful.
9) This is just leftover from me working through failures.
Comment #23
damiankloip CreditAttribution: damiankloip commentedYeah sorry, I think that may be able to go. Not sure? I originally added it so this ran after any other subscribers.
Comment #24
damiankloip CreditAttribution: damiankloip commentedNitpick: I think this comment should state this is basically to cover routes added in the dynamic_routes set.
Otherwise, I think this is looookin' good.
Comment #25
tim.plunkett@damiankloip pointed out that the priority is to help ensure this runs last, similar to content_translation having a higher module weight.
Also fixed the comment, good point.
Comment #26
damiankloip CreditAttribution: damiankloip commentedYeah, similar to why you had to add the fix to try and find the route from the current collection I guess. If its last we should always be able to find any dynamic route.
Comment #27
dawehnerThe priority is not controlled on the services level.
Comment #28
damiankloip CreditAttribution: damiankloip commentedWe are using routes(), so onDynamicRoutes and not alter ?
Comment #29
tim.plunkettRight change, wrong event. Also removing the useless one from the services.yml.
Comment #30
dawehnerYou wanted to say: good will, but just horrible execution.
Comment #31
damiankloip CreditAttribution: damiankloip commentedYeah, right idea. Wrong implementation there :-) same goes for the priority too!
This is looking good now.
Comment #32
tim.plunkettComment #34
alexpottCommitted 7b8e204 and pushed to 8.x. Thanks!
Comment #35
XanoFor more PHPUnit coverage of this change in the entity API, see #2134857: PHPUnit test the entity base classes.
Comment #36
Crell CreditAttribution: Crell commentedComment #37
Crell CreditAttribution: Crell commentedThis is potentially quite problematic. We *need* the canonical relationship there. Also, we added those link patterns originally for REST module, so that we could *generate* the routes off of the links. That is, the whole point was the other way around from what this issue just did. See #2019123: Use the same canonical URI paths as for HTML routes There's been on and off discussion of generating the HTML route off of the defined URI, too.
Really, I think this issue is a regression. :-(
Comment #38
tim.plunkettThis patch did two things at once.
It switched the "links" part of the Entity annotation to be a route name instead of a path, and it fixed up the content_translation entity routes part.
Crell is only taking issue with the annotation part, please do not roll back the content_translation hunks at the same time.
Comment #39
Crell CreditAttribution: Crell commentedWe discussed this issue at length in today's WSCCI meeting. The resolution:
* We need a new patch on this issue to roll back the switch from URI templates to routes in the entity annotations. Entity annotations must be URIs.
* We cannot just revert this patch as is, as it also fixed various translation issues.
* Once that's done, we will move the HTML route generation to be dynamic, just like the non-HTML routes. This has some implementation details we did not fully finish fleshing out, but that's a topic for a new issue.
So the action item here is: We need a patch to switch back to URI template routes, but not break the translation work here. Volunteers?
Because this is an API change, and we have 2 other issues blocked hard until this is done, I am bumping the priority.
Comment #40
damiankloip CreditAttribution: damiankloip commentedWe seriously need to stop renaming and repurposing the same issues...
Comment #41
catchYes please close this issue and open a new one, it's incredibly confusing restarting issues, messes up git blame and all kinds of other problems.
Comment #42
dawehnerHere is one: #2150747: Switch back to URI templates in entity annotations
Comment #43
tim.plunkettComment #44
effulgentsia CreditAttribution: effulgentsia commentedComment #45
Crell CreditAttribution: Crell commentedWe don't need a change notice here if we're about to undo it, do we?
Comment #46
klausiI agree, no change notice needed here since we should roll this back in #2150747: Switch back to URI templates in entity annotations.