In contrast to other performAction() implementations the one in RabbitHoleBehaviorPlugin::PageRedirect is very large and combines several aims. It mixes the determination of the $response_code, the $target AND the response creation.
On the one hand this leads to a quite long and monolithic function, on the other hand it prevents extending modules from getting the resulting $target URL object and $status_code independently from the finale response.
So what I'd suggest is to split the function into:
- performAction(EntityInterface $entity, Response $current_response = NULL) which calls and orchestrates the submethods
- getActionTarget(EntityInterface $entity) which returns the target with parent entity fallback, language handling, token replacement etc.
- getActionResponseCode(EntityInterface $entity) which returns the response code with parent entity fallback, etc.
One might discuss if only getActionTarget() is required, but getActionTarget() makes a lot of sense because of the additional logic for token replancement and language handling.
If the idea is OK for you, I'll create a patch.
Concretely I need this method in rabbit_hole_href and had to copy half of the function code so far, which is dirty, but the only possible way so far.
Comment | File | Size | Author |
---|---|---|---|
#10 | 3095653-10.patch | 6.42 KB | Matroskeen |
|
Comments
Comment #2
AnybodyThis is the code I'm talking about:
Comment #3
AnybodyPatch attached, please have a look.
Comment #4
AnybodyThere was a ->toString() that had to be removed in
to always return an URL object consistently.
Comment #5
AnybodyThe ->toString() had to be readded on the call to make things work like before:
Everything seems fine to me now. Please review!
Comment #6
AnybodyAny chance for a maintainer review here?
Comment #7
thomas.frobieterWe're using this patch #5 successfully since months now. +1 RTBC
Comment #8
Anybody@Dylan Donkersgoed: Could you perhaps have a look? It would be very helpful to have this large function more atomic for extending contrib modules. This prevents us from copying a lot of code.
Thanks a lot in advance.
Comment #9
AnybodyI can once more confirm this works well and without any problems. Any chance for a maintainer to have a look? This would really help to allow better reuse and additional modules built on this like described above. Thanks a lot!
Comment #10
MatroskeenWe have a bunch of new changes in dev branch, so here is a re-roll.
Let's see tests results.
Comment #12
MatroskeenTests are OK with those changes... so do I :)
Committed to 8.x-1.x, will be available in the next release.
Thanks!
Comment #13
AnybodyThank you very much! I'm very much looking forward to the next release which will make https://www.drupal.org/project/rabbit_hole_href compatible without patches!
Is there an estimation already when it will be released?
Comment #14
MatroskeenThe plan is the following:
Comment #15
Anybody@Matroskeen thank you very much, that sounds great! :)