Problem/Motivation
Currently, there is no way to set default url route parameters besides modifying the entity class itself, but this may not always be practical. An example would be if a module would be adding link templates / entity routes to another module's entity.
Proposed resolution
I propose creating an alter hook call in the base Entity class' urlRouteParameter()
method. See API Changes below.
Remaining tasks
Api documentation and hook already added. Needs peer review.
API changes
Entity API additions for a new alter hook hook_entity_url_route_parameters_alter()
.
There is currently another issue (#2651974: field_ui_entity_operation() cannot respect route parameters because of incorrectly named routes) that I see as slightly related in the sense that another method could be created to encapsulate urlRouteParameters(), which itself could be public (such as getRouteParameters()
), and that method could then call the alter hook after urlRouteParameters() is called to make sure that the alter hook is called after an entity's default parameters for every entity.
Comment | File | Size | Author |
---|---|---|---|
#45 | interdiff_2941880_43_45.txt | 2.47 KB | _pratik_ |
#45 | 2941880-45.patch | 6.82 KB | _pratik_ |
#45 | 2941880-44.patch | 7.1 KB | _pratik_ |
#44 | interdiff_2941880_43_44.txt | 2.19 KB | _pratik_ |
#44 | 2941880-43.patch | 7.15 KB | _pratik_ |
Comments
Comment #2
grathbone CreditAttribution: grathbone at VMLY&R commentedComment #3
grathbone CreditAttribution: grathbone at VMLY&R commentedComment #4
grathbone CreditAttribution: grathbone at VMLY&R commentedComment #5
grathbone CreditAttribution: grathbone at VMLY&R commentedWoops. This is the patch that works. Incorrectly chose the wrong patch before.
Comment #6
grathbone CreditAttribution: grathbone at VMLY&R commentedComment #7
grathbone CreditAttribution: grathbone at VMLY&R commentedComment #9
tim.plunkettMost other entity hooks would fire for the generic case and also the entity-type specific case.
The first param would change to
[$this->getEntityTypeId() . '_url_route_parameters', 'entity_url_route_parameters']
and then be documented as
hook_ENTITY_TYPE_url_route_parameters()
in addition to the one you have.Comment #10
tim.plunkettComment #12
grathbone CreditAttribution: grathbone at VMLY&R commentedMade change listed in #10.
Fixed tests to add module_handler to the container.
Comment #14
grathbone CreditAttribution: grathbone at VMLY&R commentedWoops. Rerolled for 8.6.x.
Comment #15
tim.plunkettLooks great!
Nit: replace url with URL
These tests (maybe just the EntityUrlTest, maybe both?) should be expanded to assert that the alter is called.
Comment #16
grathbone CreditAttribution: grathbone at VMLY&R commented@tim.plunkett how should I go about doing that assertion and to what extent? Do you have any examples I could look at? My UnitTest knowledge is fairly slim at this point.
Edit: Disregard. I think I found a good example.
Comment #17
grathbone CreditAttribution: grathbone at VMLY&R commentedAdded an alter hook test to
EntityUnitTest
(since toLink uses toUrl, it would be redundant to add a test toEntityLinkTest
).Also updated 'url' instances in the api documentation to 'URL'.
Comment #19
kristiaanvandeneyndeLooks good to me. Maybe Tim can confirm this is what he expected to see in the test.
Comment #22
grathbone CreditAttribution: grathbone as a volunteer commentedRerolled for 8.7.x.
Comment #24
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedUpdated for Drupal 8.8
Comment #26
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedComment #28
ravi.shankar CreditAttribution: ravi.shankar at OpenSense Labs commentedComment #30
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedComment #31
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedComment #33
anmolgoyal74 CreditAttribution: anmolgoyal74 commentedComment #34
AnybodyComment #42
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #43
Nikhil_110 CreditAttribution: Nikhil_110 at Srijan | A Material+ Company commentedAttached patch against Drupal 10.1.x
Comment #44
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedFix for failures in #43
Thanks
Comment #45
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commentedMy bad, uploaded same patch as #43 in #44.
Comment #46
_pratik_ CreditAttribution: _pratik_ as a volunteer and at Specbee for Drupal India Association commented