Problem/Motivation
Entity API documentation in core states that:
Entity routes, like other routes, are defined in *.routing.yml files; see the Routing API topic for more information. Entities may alternatively use an auto route provider class;
This wording can be interpreted as saying that the route provider class and YAML file are mutually exclusive, and developers might commit time and effort to doing it one way or the other, but not both. However, core modules e.g. the node module have both a node.routing.yml
and a NodeRouteProvider
class mentioned in the entity class annotation.
Proposed resolution
- Confirm that routing YAML and routing annotations can co-exist for entity routes (confirmed by @dawehner in comments)
- Determine the order of preference for these. (following further discussion, confirmation that YAML "wins")
- Modify the documentation to make all this clear.
If both can co-exist, a simple rewording might be:
Entity routes can be defined in one of two ways: using *.routing.yml files, as discussed in the Routing API topic; or declaring an auto route provider class in the entity class' annotations. When both YAML files and a route provider class exist, then [tbc.]
(Is "auto" a recognized term here btw, or can it be dropped?)
Remaining tasks
- Get community agreement on proposed changes to documentation.
User interface changes
None.
API changes
None.
Data model changes
None.
Comment | File | Size | Author |
---|---|---|---|
#12 | entity_routing_via_yaml-2801409-interdiff-9-12.txt | 1023 bytes | jp.stacey |
#12 | entity_routing_via_yaml-2801409-12.patch | 3.38 KB | jp.stacey |
#9 | entity_routing_via_yaml-2801409-interdiff-5-9.txt | 732 bytes | jp.stacey |
#9 | entity_routing_via_yaml-2801409-9.patch | 3.52 KB | jp.stacey |
#5 | entity_routing_via_yaml-2801409-5.patch | 3.52 KB | jp.stacey |
Comments
Comment #2
dawehnerYes, they can totally coexist.
I would frame it like that: If the annotations/default classes help you, use them. Otherwise, feel free to do what you want.
Comment #3
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commented@dawehner thanks re confirmation.
Regarding the other point, I wasn't thinking so much of "best practice advice" order of preference (is there any?) but rather - if you define a route in both places, what happens? Does one override the other?
Comment #4
dawehnerOh, conceptually I'd argue it simply shouldn't be done. The one in the annotation will win, but its really not meant to be for altering :)
Comment #5
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commented@dawehner thanks for clarifying. Patch attached for discussion.
Comment #6
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commentedComment #7
tstoecklerRe #4: Are you sure? It's been a while since I tried it out but I'm pretty sure it's the other way around.
Comment #8
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commented@tstoeckler you're quite right: I've just trialled adding a nonsense
entity.node.edit_form
route to:*
core/modules/node/node.routing.yml
*
modules/custommodule/custommodule.routing.yml
and in both cases, the existing route at
node/{node}/edit
404s. I'll set this back to "Needs work", although I think it's just a rewording required.Comment #9
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commentedPatch includes correction following experimentation with YAML/provider conflicts.
Comment #10
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commentedComment #11
dawehnerI really like these improvements!
Well, I'd argue that providers at the moment are mostly there for autogenerating stuff. Making suggestions what the better approach here is, feels kinda arbitrary.
Comment #12
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commented@dawehner thanks for the feedback. I added the advice because I felt there was a bit of a "best practice" gap there, and that's broadly how core works as far as I can see, but you're right that people might have reasons for splitting entity routes between the two.
So I've removed it, while retaining the note about avoiding route-name duplication, which I think is worth mentioning because:
* given the YAML file takes precedence, then it's not even as though autogeneration can e.g. sometimes override it, sometimes not; there's no advantage to duplication of route names that I can see.
* we weren't 100% sure when we started this thread what would happen, so it's easy to confuse other developers by duplicating route names: "what does this code do again?"
Updated patch and interdiff attached.
Comment #13
dawehner@jp.stacey
Thank you!
Comment #14
tstoecklerI know this is just being moved, but this is actually incomplete as of now. We also generate add-form, add-page and collection routes.
I would be fine fixing this in a follow-up (thus, leaving at RTBC) but wanted to bring it up so we don't forget.
Comment #15
jp.stacey CreditAttribution: jp.stacey at Magnetic Phield commented@tstoeckler granular commits would be best if that's OK, not least because I've discovered another mention of edit-form etc. elsewhere, so I'll detail that on the new issue #2820665: Entity routing documentation need other routes adding and we can discuss it there.
Comment #16
tstoecklerThat's perfect, thanks for opening that issue!
Comment #17
alexpottCommitted and pushed 96152bf to 8.3.x and ea33c32 to 8.2.x. Thanks!