function template_preprocess_search_api_page_result in Search API Pages 7
Same name and namespace in other branches
- 8 search_api_page.module \template_preprocess_search_api_page_result()
Process variables for search-result.tpl.php.
The $variables array contains the following arguments:
- $result
See also
search_api_page-result.tpl.php
File
- ./
search_api_page.pages.inc, line 377 - User page callbacks for the Search pages module.
Code
function template_preprocess_search_api_page_result(&$variables) {
$index = $variables['index'];
$variables['id'] = $variables['result']['id'];
$item = $variables['item'];
$wrapper = $index
->entityWrapper($item, FALSE);
$variables['url'] = $index
->datasource()
->getItemUrl($item);
$variables['title'] = $index
->datasource()
->getItemLabel($item);
if (!empty($variables['result']['excerpt'])) {
$variables['excerpt'] = $variables['result']['excerpt'];
$text = $variables['result']['excerpt'];
}
else {
$fields = $index->options['fields'];
$fields = array_intersect_key($fields, drupal_map_assoc($index
->getFulltextFields()));
$fields = search_api_extract_fields($wrapper, $fields);
$text = '';
$length = 0;
foreach ($fields as $field_name => $field) {
if (search_api_is_list_type($field['type']) || !isset($field['value'])) {
continue;
}
$val_length = drupal_strlen($field['value']);
if ($val_length > $length) {
$text = $field['value'];
$length = $val_length;
$format = NULL;
if (($pos = strrpos($field_name, ':')) && substr($field_name, $pos + 1) == 'value') {
$tmp = $wrapper;
try {
foreach (explode(':', substr($field_name, 0, $pos)) as $part) {
if (!isset($tmp->{$part})) {
$tmp = NULL;
}
$tmp = $tmp->{$part};
}
} catch (EntityMetadataWrapperException $e) {
$tmp = NULL;
}
if ($tmp && $tmp
->type() == 'text_formatted' && isset($tmp->format)) {
$format = $tmp->format
->value();
}
}
}
}
if ($text && function_exists('text_summary')) {
$text = text_summary($text, $format);
}
}
// Check for existence. User search does not include snippets.
$variables['snippet'] = isset($text) ? $text : '';
// Meta information
global $language;
if (isset($item->language) && $item->language != $language->language && $item->language != LANGUAGE_NONE) {
$variables['title_attributes_array']['xml:lang'] = $item->language;
$variables['content_attributes_array']['xml:lang'] = $item->language;
}
$info = array();
if (!empty($item->name)) {
$info['user'] = $item->name;
}
if (!empty($item->created)) {
$info['date'] = format_date($item->created, 'short');
}
// Provide separated and grouped meta information..
$variables['info_split'] = $info;
$variables['info'] = implode(' - ', $info);
}