upadted to 1.8

This commit is contained in:
Bachir Soussi Chiadmi
2013-09-26 15:49:26 +02:00
parent e0ae80791b
commit 128640cd15
52 changed files with 2604 additions and 1015 deletions

View File

@@ -20,14 +20,20 @@ function search_api_views_views_data() {
'help' => t('Use the %name search index for filtering and retrieving data.', array('%name' => $index->name)),
'query class' => 'search_api_views_query',
);
if (isset($entity_types[$index->item_type])) {
if (isset($entity_types[$index->getEntityType()])) {
$table['table'] += array(
'entity type' => $index->item_type,
'entity type' => $index->getEntityType(),
'skip entity load' => TRUE,
);
}
$wrapper = $index->entityWrapper(NULL, TRUE);
try {
$wrapper = $index->entityWrapper(NULL, TRUE);
}
catch (EntityMetadataWrapperException $e) {
watchdog_exception('search_api_views', $e, "%type while retrieving metadata for index %index: !message in %function (line %line of %file).", array('%index' => $index->name), WATCHDOG_WARNING);
continue;
}
// Add field handlers and relationships provided by the Entity API.
foreach ($wrapper as $key => $property) {
@@ -105,6 +111,31 @@ function search_api_views_views_data() {
$table['search_api_views_more_like_this']['title'] = t('More like this');
$table['search_api_views_more_like_this']['help'] = t('Find similar content.');
$table['search_api_views_more_like_this']['argument']['handler'] = 'SearchApiViewsHandlerArgumentMoreLikeThis';
// If there are taxonomy term references indexed in the index, include the
// "Indexed taxonomy term fields" contextual filter. We also save for all
// fields whether they contain only terms of a certain vocabulary, keying
// that information by vocabulary for later ease of use.
$vocabulary_fields = array();
foreach ($index->getFields() as $key => $field) {
if (isset($field['entity_type']) && $field['entity_type'] === 'taxonomy_term') {
$field_id = ($pos = strrpos($key, ':')) ? substr($key, $pos + 1) : $key;
$field_info = field_info_field($field_id);
if (isset($field_info['settings']['allowed_values'][0]['vocabulary'])) {
$vocabulary_fields[$field_info['settings']['allowed_values'][0]['vocabulary']][] = $key;
}
else {
$vocabulary_fields[''][] = $key;
}
}
}
if ($vocabulary_fields) {
$table['search_api_views_taxonomy_term']['group'] = t('Search');
$table['search_api_views_taxonomy_term']['title'] = t('Indexed taxonomy term fields');
$table['search_api_views_taxonomy_term']['help'] = t('Search in all indexed taxonomy term fields.');
$table['search_api_views_taxonomy_term']['argument']['handler'] = 'SearchApiViewsHandlerArgumentTaxonomyTerm';
$table['search_api_views_taxonomy_term']['argument']['vocabulary_fields'] = $vocabulary_fields;
}
}
return $data;
}
@@ -130,7 +161,7 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper
if ($inner_type == 'text') {
$table[$id] += array(
'argument' => array(
'handler' => 'SearchApiViewsHandlerArgumentText',
'handler' => 'SearchApiViewsHandlerArgument',
),
'filter' => array(
'handler' => 'SearchApiViewsHandlerFilterText',
@@ -142,6 +173,7 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper
if ($options = $wrapper->optionsList('view')) {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterOptions';
$table[$id]['filter']['options'] = $options;
$table[$id]['filter']['multi-valued'] = search_api_is_list_type($type);
}
elseif ($inner_type == 'boolean') {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterBoolean';
@@ -153,7 +185,12 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilter';
}
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgument';
if ($inner_type == 'string' || $inner_type == 'uri') {
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgumentString';
}
else {
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgument';
}
// We can only sort according to single-valued fields.
if ($type == $inner_type) {
@@ -168,12 +205,27 @@ function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper
* Implements hook_views_plugins().
*/
function search_api_views_views_plugins() {
// Collect all base tables provided by this module.
$bases = array();
foreach (search_api_index_load_multiple(FALSE) as $index) {
$bases[] = 'search_api_index_' . $index->machine_name;
}
$ret = array(
'query' => array(
'search_api_views_query' => array(
'title' => t('Search API Query'),
'help' => t('Query will be generated and run using the Search API.'),
'handler' => 'SearchApiViewsQuery'
'handler' => 'SearchApiViewsQuery',
),
),
'cache' => array(
'search_api_views_cache' => array(
'title' => t('Search-specific'),
'help' => t("Cache Search API views. (Other methods probably won't work with search views.)"),
'base' => $bases,
'handler' => 'SearchApiViewsCache',
'uses options' => TRUE,
),
),
);