diff --git a/contrib/search_api_views/search_api_views.module b/contrib/search_api_views/search_api_views.module index 8a131c2..b185472 100644 --- a/contrib/search_api_views/search_api_views.module +++ b/contrib/search_api_views/search_api_views.module @@ -15,6 +15,18 @@ function search_api_views_views_api() { } /** + * Implements hook_module_implements_alter(). + */ +function search_api_views_module_implements_alter(&$implementations, $hook) { + // Ensure our views data alter runs after VBO so we can test for support. + if ($hook == 'views_data_alter' && isset($implementations['views_bulk_operations'])) { + $group = $implementations['search_api_views']; + unset($implementations['search_api_views']); + $implementations['search_api_views'] = $group; + } +} + +/** * Implements hook_search_api_index_insert(). */ function search_api_views_search_api_index_insert() { diff --git a/contrib/search_api_views/search_api_views.views.inc b/contrib/search_api_views/search_api_views.views.inc index a87e5bc..552339d 100644 --- a/contrib/search_api_views/search_api_views.views.inc +++ b/contrib/search_api_views/search_api_views.views.inc @@ -158,6 +158,42 @@ function search_api_views_views_data() { } /** + * Implements hook_views_data(). + */ +function search_api_views_data_alter(&$data) { + // See if VBO is installed. + if (module_exists('views_bulk_operations')) { + $entity_types = entity_get_info(); + + // Loop over our search indexes and see if we can add VBO support. + foreach (search_api_index_load_multiple(FALSE) as $index) { + $key = 'search_api_index_' . $index->machine_name; + + // Check this is exposed to views. + if (!isset($data[$key])) { + continue; + } + + // Check supports generic for entity tables and this entity type. + // @see https://www.drupal.org/comment/8381773#comment-8381773 + $entity_type = $index->getEntityType(); + if (!empty($data['views_entity_' . $entity_type]['views_bulk_operations'])) { + $table['views_bulk_operations'] = array( + 'title' => $index->name, + 'group' => t('Bulk operations'), + 'help' => t('Provide a checkbox to select the row for bulk operations.'), + 'real field' => $entity_types[$entity_type]['entity keys']['id'], + 'field' => array( + 'handler' => 'views_bulk_operations_handler_field_operations', + 'click sortable' => FALSE, + ), + ); + } + } + } +} + +/** * Adds handler definitions for a field to a Views data table definition. * * Helper method for search_api_views_views_data().