Updated: Comment #0
Problem/Motivation
Most config entities follow a common pattern.
- A list page.
- An edit page and tab.
- A delete page and form.
- An add page.
- An optional enable/disable page/callback (when there is a status entity key defined).
- Most of these point to entity forms and list controllers anyway ie there are no true controllers, and the enable/disable can be generalized for most use cases.
As a proof of concept, this patch demonstrates its functionality by removing contact.routing.yml which (at this stage) only points to the routes above.
Note that if you want to change the path (ie keep routing separate from paths) you can still hook_entity_info_alter(), change the 'admin_path' and it will keep working. Note this patch generates route ids of the form {module}.{entity_type}_list|add|edit|delete etc.
Proposed resolution
Dynamically generate the routes for a better DX.
Remaining tasks
Review
User interface changes
None
API changes
A new 'admin_path' and 'admin_permission' annotation entry added for config entities.
Comment | File | Size | Author |
---|---|---|---|
#31 | interdiff-28-31.txt | 1.25 KB | martin107 |
#31 | entity_route_building-2089757-31.patch | 6.52 KB | martin107 |
#28 | entity_route_building-2089757-28.patch | 6.54 KB | martin107 |
#25 | entity_route_building-2089757-25.patch | 6.58 KB | dawehner |
config-entity-admin-path.patch | 10.95 KB | larowlan | |
Comments
Comment #1
larowlanunintended, will remove in next patch
Comment #2
andypost+1 here, awesome idea!
Comment #3
larowlanComment #4
larowlanRelated #2089767: Provide a ConfigDeleteFormBase to cover common functionality of config entity delete forms
Comment #4.0
larowlanUpdated issue summary.
Comment #5
larowlanGreen! flabbergasted
Comment #6
Gábor HojtsyIMHO it would be vital that we rely on the same path/route definition mechanism that entities use already. See #2083615: Use links annotation for config entity URI like for content entities where I propose to reuse the same links{} structure that is widespread for content entities. That lets us remove the url() method implementations for most entities. I see this just proposes we establish a common URL structure for list/add/edit/delete for all config entities. I think that is in itself a good goal, but it would be good to reconcile that with how content entities do this, so we can share implementations / know-how and not a custom implementation for config entities only. My approach for the instance URLs at least solves that for the instances. It does not provide a way to autogenerate the listing but at least from the instance level, it would equally let you autogenerate. Maybe we should just use the list url link type in the links array?
Comment #7
Gábor HojtsyComment #8
larowlanAgree completely, lets postpone this on #2083615: Use links annotation for config entity URI like for content entities and come back to supplement the 'edit-link' added there with additional 'add-link', 'list-link' and 'delete-link' entries.
Will try and review that one later today.
Comment #9
larowlanComment #10
BerdirBeing able to specify a basic permission (possibly even separate ones per operation?) is something I always wanted to do, maybe we can do that in a separate issue, I think it's quite unrelated to the routing stuff?
And +1 on using the links stuff for this.
Comment #11
Gábor Hojtsy#2083615: Use links annotation for config entity URI like for content entities landed and can now be built off of, yay! :)
Comment #11.0
Gábor HojtsyUpdated issue summary.
Comment #12
tim.plunkettI think #1783964: Allow entity types to provide menu items would be suitably covered by this, should we mark that as a duplicate?
Comment #13
klonosComment #14
catchMarked #1783964: Allow entity types to provide menu items as duplicate.
Comment #15
larowlanbump (I keep losing this)
Comment #16
dawehnerI will try to work on it.
Comment #17
BerdirThis is fun as long as you want it exactly standardized. Looking at core, many entity types have some special cases and handling.
The part that I'm worried about is when it's magically generated, is that it's going to be a) harder to understand and b) harder to extend/alter when you don't want it to work exactly like the generated standard.
I'm wondering if we should pursue code scaffolding approaches instead, that generate a routing file (for example) for you, that you can then easily change and customize as you need to.
Comment #18
XanoAt the very least this needs work, because the routes use permissions directly rather than entity access, which is a bug and a possible security problem.
I also agree with what @Berdir said in #17: this works fine for a few entities in core, but not for all of them, let alone the ones in contrib. It also only takes some operations into account. What about #2201137: Introduce a "duplicate" entity operation, for instance?
Comment #19
andypostSuppose this suitable for the most of config entities, they just need "administer" permission, but fields and instances...
Comment #20
Gábor HojtsyThis looks like a very similar problem to #2150747: Switch back to URI templates in entity annotations where generating those routes is also of key discussion now.
Comment #21
dawehnerFrom my perspective the motivation is not based upon any kind of core usecase or other issue. The goal for this issue, as far as I understand the initial post is not some kind of unification, some kind of having to write less. The goal is to make the out of box DX better.
You just write your basic $entity.php file and you get some kind of admin UI for free. Yes, in the real world most entity types might need some kind of customization but you get a lot of nicer experience on the way to your final code. For example provide an add/edit/delete form out of the box would really help you to write the entity type. Additional some kind of listing (implementation differs with your personal taste) would also help you on the way.
Maybe both goals (unification/autogeneration and the better DX during development) lead to similar/the same solutions, but I just wanted to write down the thoughts.
Comment #22
catchThis blocks two critical issues atm, so bumping to critical.
Comment #23
tim.plunkettWhoops, guess this missed the actual critical part.
Comment #24
dawehnerThere is simply no reason EVER to use the assigned flag. You simply cannot trust people to work on something.
Regarding the actual issue. My primary usecase was developer experience during developing code, so you have at least something which can be shown really fast.
I didn't expected to actually use automatic route generation for production code, which seems to be the usecase of this issue.
Comment #25
dawehnerHere is a basic start.
Comment #27
tstoecklerYay, for working on this!
@dawehner++++++
I don't think we should support this, as it's really a test-only use-case. Couldn't we rather have an EntityTestAccessController, that always returns TRUE?
Awesome! This will allow us to expand this to more templates later on.
Comment #28
martin107 CreditAttribution: martin107 commentedreroll of #25.
1 conflict resolved in the area of of RouteBulder
locally RouteBuilderTest is green.
Comment #30
tim.plunkettWhy would this be a Controller?
Comment #31
martin107 CreditAttribution: martin107 commented1) #31 I agree it makes no sense ControllerBase.. removed
2) Trivial update of Contains comment to reflect the correct class/filename.
Just pulling information together from test logs... while I mull things over.
The following tests fail with one of two common failure routes.
Tests
TermFieldTest, CustomBlockCacheTest, TermCacheTagsTest, DataTimeFieldTest
Routes
/entiy_test/{entity_test}
OR
/entity_test/delete/entity_test/{entity_test}
Comment #32
martin107 CreditAttribution: martin107 commentedComment #34
dawehner#2281645: Make entity annotations use link templates instead of route names is needed for this
Comment #35
jhodgdonSee also #2316171: [meta] Improve DX of entity defining (if you want a UI)
Comment #36
dawehnerLet's be a little bit more honest.
Comment #37
tim.plunkett:)
Comment #38
xjmComment #39
xjmComment #40
BerdirI'm not quite sure why/how this is blocking criticals? Is it not the other way round?
Comment #41
catchThis is postponed on #2281645: Make entity annotations use link templates instead of route names which is major, so yes I don't think it's blocking any critical issues, and nor is it critical. If we add a bc layer where routes don't get auto-generated there's no API change.
Comment #42
dawehnerSounds like a clear duplicate of #2350509: Implement auto-route generation for all core entities and convert all of the core entities. at this point.