diff --git a/contrib/search_api_views/includes/query.inc b/contrib/search_api_views/includes/query.inc index 958ee7a..b205599 100644 --- a/contrib/search_api_views/includes/query.inc +++ b/contrib/search_api_views/includes/query.inc @@ -180,6 +180,30 @@ class SearchApiViewsQuery extends views_plugin_query { } /** + * Add a field to the query table. This is a proxy method for addField(), + * compatible with views_plugin_query_default::add_field(). Only the + * $field parameter is used. + * + * @param $table + * This parameter is ignored. + * @param $field + * The name of the field to add. This may be a real field or a formula. + * @param $alias + * This parameter is ignored. + * @param $params + * This parameter is iggit statnored. + * + * @see views_plugin_query_default::add_field() + * + * @return $name + * The field's identifier, as used by the Search API. E.g., "title" for a + * node's title, "author:name" for a node's author's name. + */ + function add_field($table, $field, $alias = '', $params = array()) { + return $this->addField($field); + } + + /** * Defines the options used by this query plugin. * * Adds some access options. diff --git a/contrib/search_api_views/search_api_views.module b/contrib/search_api_views/search_api_views.module index 8a131c2..05f8084 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']) && isset($implementations['search_api_views'])) { + $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 ff52d69..5072fef 100644 --- a/contrib/search_api_views/search_api_views.views.inc +++ b/contrib/search_api_views/search_api_views.views.inc @@ -153,6 +153,42 @@ function search_api_views_views_data() { } /** + * Implements hook_views_data_alter(). + */ +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().