Integrating with Search API
Last updated on
30 April 2025
Right now VBO doesn't work out of the box on Views that use Search API.
There is work in progress to rectify that by making VBO a backend-agnostic Views field (#1334374: Re-use generic entity views table),
currently blocked by the lack of revision support in the backend-agnostic Views field code.
In the meantime, a small module is needed.
The current working code was first posted by drewish in #1123454: Integration with views bulk operations (vbo).
It is meant to be placed in a vbo_search_api module.
/**
* Implements hook_views_data_alter().
*/
function vbo_search_api_views_data_alter(&$data) {
if (isset($data['search_api_index'])) {
foreach (search_api_index_load_multiple(FALSE) as $index) {
$data['search_api_index_' . $index->machine_name]['views_bulk_operations'] = array(
'title' => t('Bulk operations'),
'help' => t('Provide a checkbox to select the row for bulk operations.'),
'real field' => 'id',
'field' => array(
'handler' => 'vbo_search_api_handler_field_operations',
'item_type' => $index->item_type,
'click sortable' => FALSE,
),
);
}
}
}
class vbo_search_api_handler_field_operations extends views_bulk_operations_handler_field_operations {
/**
* Override their get entity type since the base table name won't match at all.
*/
function get_entity_type() {
return $this->definition['item_type'];
}
/**
* Overridden to try to fish out the id.
*/
public function get_value($values, $field = NULL) {
// I'm not sure this is the best source for this but the name seemed consistent.
return $values->_entity_properties['search_api_item_id'];
}
}
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion