Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
While porting https://www.drupal.org/project/entity_is_public to Drupal 8 I found that I need a way to test the Rabbit Hole action for different scenarios.
\Drupal\rabbit_hole\BehaviorInvoker::processEntity() returns either a response object or NULL. I tried working my way out of that but I realized that I could do way more specific tests by making \Drupal\rabbit_hole\BehaviorInvoker::getRabbitHoleValuesForEntity() public and checking for each specific action than inspecting response objects.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2958548-11.patch | 1.59 KB | Anybody |
#2 | rabbit_hole-2958548-2.patch | 608 bytes | juampynr |
Comments
Comment #2
juampynr CreditAttribution: juampynr at Lullabot commentedHere is a patch that changes the access modifier to public.
Comment #3
deviantintegral CreditAttribution: deviantintegral at Lullabot commentedDoes it make more sense for this method to always return a response, modified or not? That would save callers from having to check for null returns. I think it's fine as a different issue and patch, I was just looking based on your issue description.
Otherwise, this patch looks good to me.
Comment #4
juampynr CreditAttribution: juampynr at Lullabot commentedThere is a higher level method that calls this one that returns a response or NULL. I feel that it was overhead to go through that instead of exposing this method.
Comment #5
juampynr CreditAttribution: juampynr at Lullabot commentedActually, now that I have got the tests passing, I will try inspecting the response and see if I get the same results. That would mean that this patch is not required.
Comment #6
juampynr CreditAttribution: juampynr at Lullabot commentedFixed at https://github.com/juampynr/entity_is_public/commit/15677b60cdcad8754d79.... The patch is no longer necessary. However, I will leave this open as it may be useful to have that method available as part of the Rabit Hole API.
Comment #7
firewaller CreditAttribution: firewaller commentedWhen I use the code from GitHub in a custom module I get the following error:
Any ideas?
Comment #8
firewaller CreditAttribution: firewaller commentedI missed the NULL check:
I updated my code to:
Nevermind. Thank you!
Comment #9
AnybodySame here! :)
I've been struggling around with this problem for several days now for rabbit_hole_href module and rh is too strict and too less separated in this case (while it's a wonderful module!). Other modules extending rh need better ways to figure out which entities are affected by rh and how. Drupal is built on extensions and I think rh is now that common that it should also allow other modules to extend it for special use cases as best as possible.
Of course you "could" write workarounds like in #6 based on processEntity() but to analyze the returned response is very dirty and the module could use some API love here :)
In my concrete example what I needed was, given just an entity type + bundle name OR an entity object, information about its configured rh behavior.
What rh currently misses as public functions / services is:
I'll write a patch as soon as possible, it would be nice to have some rh maintainer feedback in the meantime?
Thank you all!
Comment #10
AnybodyRelated issue for better access to rabbit_hole information from other modules: #3095653: Split performAction() into submethods in PageRedirect Behaviour
Comment #11
AnybodyPatch attached based on #2 which also adds public function getRabbitHoleValuesForEntityType($entity_type_id, $bundle_id = NULL) to retrieve the configuration for an entity type + bundle in cases where no entity object exists.
Please review and feedback.
Comment #12
AnybodyCould a maintainer perhaps have a look at the patch in #11? We're using it since that date in production and it works perfectly. Would be nice to have this reviewed. Thank you very much.
Comment #13
thomas.frobieterWe're using patch #11 successfully since months now. +1 RTBC
Comment #15
Dylan Donkersgoed CreditAttribution: Dylan Donkersgoed as a volunteer commentedOnly real problem I see with this is that the method probably should be in the interface as well, but the already existing public method doesn't do that either so it's probably not really in scope for this issue. Merged this in. Thanks Anybody and juampynr for the patch and thomas.frobieter for confirming it's functioning long term on your site.
Comment #16
AnybodyGreat, thank you Dylan! One patch less! YAY! :)
Looking forward to the next stable release.