Problem

Edit module uses a custom made-up way to upcast URL arguments from the request. Drupal core got standard upcasting features in the meantime in #1798214: Upcast request arguments/attributes to full objects, so edit should use that.

Proposal

Slightly extend the core upcasting feature, so it can take an entity type and an entity as separate variables and upcast from there.

Comments

gábor hojtsy’s picture

Status: Active » Needs review
StatusFileSize
new3.04 KB

All right I took the patch from @effulgentsia at #1798214-158: Upcast request arguments/attributes to full objects and just slightly modified it (added plenty comments and fixed some spacing). I was looking for test coverage for this in the codebase to update but could not find. This would need to be done for #1901100: Make Edit module work with TempStore, so revisions are not saved on all atomic field edits as well.

gábor hojtsy’s picture

StatusFileSize
new45.54 KB
new2.67 KB

Added quick test coverage. Looking at #1798214: Upcast request arguments/attributes to full objects obviously helped me find the test coverage's location :)

gábor hojtsy’s picture

StatusFileSize
new5.72 KB

Heh, that was a bit too much code :D Another patch crept in. The interdiff was authentic though.

wim leers’s picture

I"m not the right person to review this.

I can provide nitpicky feedback though :) Sorry, Gábor!

+++ b/core/lib/Drupal/Core/ParamConverter/EntityConverter.phpundefined
@@ -87,10 +93,21 @@ public function process(array &$variables, Route $route, array &$converted) {
+      // Handle an entity_type / entity pair in the path taking the value of

No spaces around the slash?

+++ b/core/lib/Drupal/Core/ParamConverter/EntityConverter.phpundefined
@@ -87,10 +93,21 @@ public function process(array &$variables, Route $route, array &$converted) {
+      if ($name == 'entity_type') {

We can use strict comparison here, so why not?

+++ b/core/lib/Drupal/Core/ParamConverter/EntityConverter.phpundefined
@@ -87,10 +93,21 @@ public function process(array &$variables, Route $route, array &$converted) {
+      if ($type == 'entity') {

Again, why not strict?

Status: Needs review » Needs work

The last submitted patch, edit-upcasting-3.patch, failed testing.

gábor hojtsy’s picture

I did not put the slashes without spaces, so it may be clearer I'm not saying these should immediately follow each other in the URL. :) I can remove the spaces though.

wim leers’s picture

Makes sense :) Nitpickfail :)

gábor hojtsy’s picture

Status: Needs work » Needs review
StatusFileSize
new4.28 KB
new6.63 KB

All right, so that review comment ignited some thinking for me though that maybe supporting only the order of entity_type/entity is a limitation. We'd need to have added error handling code for it (the code in prior patches just assumed people would follow docs and fail if you had the wrong order if there is an unknown entity type, making Drupal attempt to get a storage controller for an unknown entity type).

The code below assumes the entity type is vetted, so we should make sure it is vetted even if there was no entity_type key in the path or the value provided there was wrong (even if it came AFTER the 'entity' key). So I added some very little code for that case, so we can now support the params in any order, it can be node/12 or 12/node whatever. Added tests to test for that too.

Also fixed the fail which was due to a copy-paste issue :D

gábor hojtsy’s picture

StatusFileSize
new1.01 KB
new6.94 KB

And while I'm there, I should add tests for an invalid entity type anyway :) This proves there are no problems, the entity type list limitation works well.

Status: Needs review » Needs work
Issue tags: -sprint, -Spark

The last submitted patch, edit-upcasting-9.patch, failed testing.

gábor hojtsy’s picture

Status: Needs work » Needs review

#9: edit-upcasting-9.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, edit-upcasting-9.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
Issue tags: +sprint, +Spark

#9: edit-upcasting-9.patch queued for re-testing.

fubhy’s picture

While the patch is perfectly good code-wise it moves even further down the same magic routing rabbit hole that we are currently trying to drag ourselves out of again in #1943846: Improve ParamConverterManager and developer experience for ParamConverters.

So if this currently blocks the progress of the Edit module I'd say "Commit it" but be aware that it is VERY likely that we will have to completely change it again later. I want to solve this with #1837388: Provide a ParamConverter than can upcast any entity. which has been sitting there for quite some time without any comments but I am sure there are many places where 'interdependent upcasting' would be useful. Anyways, I am thinking of something that would go hand-in-hand with the effort from #1943846: Improve ParamConverterManager and developer experience for ParamConverters like so:

 entity.path:
   pattern: '/some/entity/path/{entity_type}/{entity}'
   options:
    parameters:
      entity:
        entity: '{entity_type}'
gábor hojtsy’s picture

Status: Needs review » Closed (won't fix)
Issue tags: -sprint

Well, this is needed as much for #1901100: Make Edit module work with TempStore, so revisions are not saved on all atomic field edits that we'd need to add a couple more classes to intervene in to handle the path for that patch (which mostly copy-paste existing code from elsewhere). If this is a workaround and that is a workaround, we can just use that workaround. I don't want to step on people's toes (and make blockers for my own issues that don't progress specifically).