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
|
|
|
*/
|
|
|
|
|
2015-08-31 07:51:38 +00:00
|
|
|
use Drupal\Component\Utility\UrlHelper;
|
2014-06-10 16:52:58 +00:00
|
|
|
use Drupal\Core\Language\LanguageInterface;
|
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) {
|
2014-02-26 19:16:54 +00:00
|
|
|
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
|
2010-11-21 20:36:36 +00:00
|
|
|
|
2007-10-31 18:06:38 +00:00
|
|
|
$result = $variables['result'];
|
2015-08-31 07:51:38 +00:00
|
|
|
$variables['url'] = UrlHelper::stripDangerousProtocols($result['link']);
|
2015-08-27 14:42:23 +00:00
|
|
|
$variables['title'] = $result['title'];
|
2014-10-13 09:10:32 +00:00
|
|
|
if (isset($result['language']) && $result['language'] != $language_interface->getId() && $result['language'] != LanguageInterface::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'])) {
|
2015-08-27 14:42:23 +00:00
|
|
|
$info['plugin_id'] = $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;
|
2015-02-13 13:10:41 +00:00
|
|
|
$variables['info'] = array(
|
|
|
|
'#type' => 'inline_template',
|
|
|
|
'#template' => '{{ info|safe_join(" - ") }}',
|
|
|
|
'#context' => array('info' => $info),
|
|
|
|
);
|
2007-09-05 08:39:57 +00:00
|
|
|
}
|