2007-09-05 08:39:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2013-02-04 19:11:11 +00:00
|
|
|
* User page callbacks for the Search module.
|
2007-09-05 08:39:57 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-25 20:12:45 +00:00
|
|
|
use Drupal\Core\Language\Language;
|
2013-09-29 07:19:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme_suggestions_HOOK().
|
|
|
|
*/
|
|
|
|
function search_theme_suggestions_search_result(array $variables) {
|
|
|
|
return array('search_result__' . $variables['plugin_id']);
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-02 10:25:52 +00:00
|
|
|
* Prepares variables for individual search result templates.
|
2007-09-05 08:39:57 +00:00
|
|
|
*
|
2013-04-02 10:25:52 +00:00
|
|
|
* Default template: search-result.html.twig
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2013-02-04 19:11:11 +00:00
|
|
|
* An array with the following elements:
|
2013-04-02 10:25:52 +00:00
|
|
|
* - result: Individual search result.
|
2013-09-06 08:26:26 +00:00
|
|
|
* - plugin_id: Plugin the search results came from.
|
2013-04-02 10:25:52 +00:00
|
|
|
* - title_prefix: Additional output populated by modules, intended to be
|
|
|
|
* displayed in front of the main title tag that appears in the template.
|
|
|
|
* - title_suffix: Additional output populated by modules, intended to be
|
|
|
|
* displayed after the main title tag that appears in the template.
|
|
|
|
* - title_attributes: HTML attributes for the title.
|
|
|
|
* - content_attributes: HTML attributes for the content.
|
2007-09-05 08:39:57 +00:00
|
|
|
*/
|
2007-10-31 18:06:38 +00:00
|
|
|
function template_preprocess_search_result(&$variables) {
|
2013-05-25 20:12:45 +00:00
|
|
|
$language_interface = language(Language::TYPE_INTERFACE);
|
2010-11-21 20:36:36 +00:00
|
|
|
|
2007-10-31 18:06:38 +00:00
|
|
|
$result = $variables['result'];
|
|
|
|
$variables['url'] = check_url($result['link']);
|
|
|
|
$variables['title'] = check_plain($result['title']);
|
2013-06-29 10:56:53 +00:00
|
|
|
if (isset($result['language']) && $result['language'] != $language_interface->id && $result['language'] != Language::LANGCODE_NOT_SPECIFIED) {
|
2012-08-03 15:31:18 +00:00
|
|
|
$variables['title_attributes']['lang'] = $result['language'];
|
|
|
|
$variables['content_attributes']['lang'] = $result['language'];
|
2010-11-21 20:36:36 +00:00
|
|
|
}
|
2007-10-31 18:06:38 +00:00
|
|
|
|
2007-09-05 08:39:57 +00:00
|
|
|
$info = array();
|
2013-09-06 08:26:26 +00:00
|
|
|
if (!empty($result['plugin_id'])) {
|
|
|
|
$info['plugin_id'] = check_plain($result['plugin_id']);
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
2007-10-31 18:06:38 +00:00
|
|
|
if (!empty($result['user'])) {
|
|
|
|
$info['user'] = $result['user'];
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
2007-10-31 18:06:38 +00:00
|
|
|
if (!empty($result['date'])) {
|
2009-08-25 10:27:15 +00:00
|
|
|
$info['date'] = format_date($result['date'], 'short');
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
2007-10-31 18:06:38 +00:00
|
|
|
if (isset($result['extra']) && is_array($result['extra'])) {
|
|
|
|
$info = array_merge($info, $result['extra']);
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
2007-10-31 18:06:38 +00:00
|
|
|
// Check for existence. User search does not include snippets.
|
|
|
|
$variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
|
|
|
|
// Provide separated and grouped meta information..
|
|
|
|
$variables['info_split'] = $info;
|
|
|
|
$variables['info'] = implode(' - ', $info);
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|
|
|
|
|