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 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.
Proposed resolution
Quick and dirty hack : clone the ViewsBulkOperationsViewData so the original one is not overridden.
Remaining tasks
Find a more suitable solution to the problem.