function _search_api_views_add_handlers in Search API 7
Adds handler definitions for a field to a Views data table definition.
Helper method for search_api_views_views_data().
Parameters
$id: The internal identifier of the field.
array $field: Information about the field.
EntityMetadataWrapper $wrapper: A wrapper providing further metadata about the field.
array $table: The existing Views data table definition, as a reference.
1 call to _search_api_views_add_handlers()
- search_api_views_views_data in contrib/
search_api_views/ search_api_views.views.inc - Implements hook_views_data().
File
- contrib/
search_api_views/ search_api_views.views.inc, line 170 - Views hook implementations for the Search API Views module.
Code
function _search_api_views_add_handlers($id, array $field, EntityMetadataWrapper $wrapper, array &$table) {
$type = $field['type'];
$inner_type = search_api_extract_inner_type($type);
if (strpos($id, ':')) {
entity_views_field_definition($id, $wrapper
->info(), $table);
}
$id = _entity_views_field_identifier($id, $table);
$table += array(
$id => array(),
);
if ($inner_type == 'text') {
$table[$id] += array(
'argument' => array(
'handler' => 'SearchApiViewsHandlerArgumentString',
),
'filter' => array(
'handler' => 'SearchApiViewsHandlerFilterText',
),
);
return;
}
$info = $wrapper
->info();
if (isset($info['options list']) && is_callable($info['options list'])) {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterOptions';
$table[$id]['filter']['multi-valued'] = search_api_is_list_type($type);
}
elseif ($inner_type == 'boolean') {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterBoolean';
}
elseif ($inner_type == 'date') {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterDate';
}
elseif (isset($field['entity_type']) && $field['entity_type'] === 'user') {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterUser';
}
elseif (isset($field['entity_type']) && $field['entity_type'] === 'taxonomy_term') {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterTaxonomyTerm';
$field_info = field_info_field($info['name']);
// For the "Parent terms" and "All parent terms" properties, we can
// extrapolate the vocabulary from the parent in the selector. (E.g.,
// for "field_tags:parent" we can use the information of "field_tags".)
// Otherwise, we can't include any vocabulary information.
if (!$field_info && ($info['name'] == 'parent' || $info['name'] == 'parents_all')) {
if (!empty($table[$id]['real field'])) {
$parts = explode(':', $table[$id]['real field']);
$field_info = field_info_field($parts[count($parts) - 2]);
}
}
if ($vocabulary = _search_api_views_get_field_vocabulary($field_info)) {
$table[$id]['filter']['vocabulary'] = $vocabulary;
}
}
elseif (in_array($inner_type, array(
'integer',
'decimal',
'duration',
'string',
'uri',
))) {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilterNumeric';
}
else {
$table[$id]['filter']['handler'] = 'SearchApiViewsHandlerFilter';
}
if ($inner_type == 'string' || $inner_type == 'uri') {
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgumentString';
}
elseif ($inner_type == 'date') {
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgumentDate';
}
else {
$table[$id]['argument']['handler'] = 'SearchApiViewsHandlerArgument';
}
// We can only sort according to single-valued fields.
if ($type == $inner_type) {
$table[$id]['sort']['handler'] = 'SearchApiViewsHandlerSort';
if (isset($table[$id]['field'])) {
$table[$id]['field']['click sortable'] = TRUE;
}
}
}