Problem/Motivation
On Drupal 11, because of some cache unserialization done by search_api, ViewsBulkOperationsBulkForm is instantiated twice, and so the ViewsBulkOperationsViewData service is initialized twice too. First with the valid original view, and then with the view unserialized from cache.
Sadly, the unserialized view is always empty for some reason, so it totally breaks VBO as it uses both objects simultaneously in the viewsForm method below:
// Only add the bulk form options and buttons if
// there are results and any actions are available.
$action_options = $this->getBulkOptions();
if (!empty($this->view->result) && !empty($action_options)) {
// Get bulk form keys and entity labels for all rows.
$entity_data = $this->viewData->getViewEntityData();
First we use $this->view->result from the original valid view object and then $this->viewData->getViewEntityData() which uses the result from the unserialized view which is always empty.
So we get in an inconsistent state that breaks VBO.
Steps to reproduce
Use VBO with search_api on Drupal 11.
Here is the code in Search API that gets the View from cache:
Here is the code in Views that calls initHandlers during unserialization:
Proposed resolution
Quick and dirty hack : clone the ViewsBulkOperationsViewData object so the original one is not overridden during the second init call.
Remaining tasks
Find a more suitable and/or permanent solution to the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | views_bulk_operations-3485284-MR93-5.patch | 802 bytes | mably |
Issue fork views_bulk_operations-3485284
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mably commentedComment #3
mably commentedComment #5
mably commentedComment #6
mably commentedComment #7
mably commentedComment #8
mably commentedOk, it looks like the View shouldn't have been serialized but only some data like the View results.
In fact the search_api module adds some dependency to the ViewExecutable in the following code:
https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/src/Plugin/views/query/SearchApiQuery.php?ref_type=heads#L285
The query gets serialized and though, the full ViewExecutable comes with it.
So it may be a bug on search_api side.
But could we try to handle it properly on VBO side?
Comment #9
mably commentedComment #10
scottm316 commentedThis definitely fixes the problem for me. Thanks a lot!