diff --git a/contrib/search_api_views/includes/query.inc b/contrib/search_api_views/includes/query.inc index 958ee7a..958470b 100644 --- a/contrib/search_api_views/includes/query.inc +++ b/contrib/search_api_views/includes/query.inc @@ -180,6 +180,31 @@ public function add_orderby($table, $field = NULL, $order = 'ASC', $alias = '', } /** + * Adds a field to the query table. + * + * This is copied from the views_plugin_query_default class so that + * third-party modules which assume it's always present will work correctly + * with Search API Views. + * + * @param string $table + * Ignored. + * @param string $field + * The name of the field to add. + * @param string $alias + * Ignored. + * @param array $params + * Ignored. + * + * @return string + * The name of the field added. + * + * @see SearchApiViewsQuery::addField + */ + 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..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 ff52d69..1221933 100644 --- a/contrib/search_api_views/search_api_views.views.inc +++ b/contrib/search_api_views/search_api_views.views.inc @@ -153,6 +153,44 @@ function search_api_views_views_data() { } /** + * Implements hook_views_data_alter(). + */ +function search_api_views_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; + + // Make sure that the table is actually there. + if (!isset($data[$key])) { + continue; + } + + $table = &$data[$key]; + + // Verify that VBO is using the entity-generic tables for its + // functionality. See #1334374. + $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().