- 🇺🇸United States rymcveigh
Thank you for documenting this. It helped us resolve the same issue with a custom module.
- 🇨🇴Colombia jasonac91
This patch addresses an issue where the access() method could potentially return a boolean instead of an expected AccessResult object in the ViewsBulkOperationsActionProcessor class. This was causing a fatal error ("Call to a member function isAllowed() on bool") when attempting to call isAllowed() on what was assumed to be an AccessResult object but was actually a boolean value.
The provided solution adds a check to ensure that the $accessResult variable is indeed an object and specifically that it possesses the isAllowed() method before attempting to call it. This check prevents the fatal error by verifying the type and method existence:
The patch first checks if $accessResult is an object and if it has the method isAllowed using PHP's is_object() and method_exists().
If these checks pass, it processes to verify if the access is allowed.
If $accessResult is not an object or does not have the isAllowed() method, it logs an error stating that the access result is not a valid AccessResult object. This helps in identifying configuration or code issues that might be causing unexpected return types.
By implementing this, we ensure the robustness of the process() function in handling cases where the action might not adhere to the expected return type conventions. This change is crucial for maintaining the stability and reliability of bulk operations within Views Bulk Operations, especially in complex environments where different actions might be configured to return non-standard access results.This patch is attached for review and testing. It has been tested in my local environment where the issue was replicated and verified that the patch resolves the problem without affecting the existing functionalities.
- Status changed to Downport
3 days ago 9:00am 19 December 2024 - 🇮🇳India nitinpatil
I'm getting an error while using the VBO action to resubmit applications in my custom module (PHP 8.3, VBO 4.3.2).
Call to a member function isAllowed() on true in Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor->process() (line 422 of /code/web/modules/contrib/views_bulk_operations/src/Service/ViewsBulkOperationsActionProcessor.php).
To resolve this issue, the following line in the code was replaced:
if ($accessResult->isAllowed() === FALSE) {with:
// Only call isAllowed() if $accessResult is an instance of AccessResultInterface
if ($accessResult instanceof AccessResultInterface && $accessResult->isAllowed() === FALSE) {The attached patch addresses this problem. It has been tested in my local environment, where the issue was reproduced, and confirmed to resolve the error without impacting existing functionality. Please review and test it further.
- 🇵🇱Poland Graber
I see the documentation got updated and the issue description stayed the same.
- 🇺🇸United States greggles Denver, Colorado, USA
I think comment #10 got flagged by the d.o auto moderation system. I've published it and confirmed nitinpatil's account so that won't happen again. Welcome nitinpatil and thanks for your comment on this issue!