Backup of db before drupal security update
[yaffs-website] / web / core / modules / search / search.pages.inc
1 <?php
2
3 /**
4  * @file
5  * User page callbacks for the Search module.
6  */
7
8 use Drupal\Component\Utility\UrlHelper;
9 use Drupal\Core\Language\LanguageInterface;
10
11 /**
12  * Implements hook_theme_suggestions_HOOK().
13  */
14 function search_theme_suggestions_search_result(array $variables) {
15   return ['search_result__' . $variables['plugin_id']];
16 }
17
18 /**
19  * Prepares variables for individual search result templates.
20  *
21  * Default template: search-result.html.twig
22  *
23  * @param array $variables
24  *   An array with the following elements:
25  *   - result: Individual search result.
26  *   - plugin_id: Plugin the search results came from.
27  *   - title_prefix: Additional output populated by modules, intended to be
28  *     displayed in front of the main title tag that appears in the template.
29  *   - title_suffix: Additional output populated by modules, intended to be
30  *     displayed after the main title tag that appears in the template.
31  *   - title_attributes: HTML attributes for the title.
32  *   - content_attributes: HTML attributes for the content.
33  */
34 function template_preprocess_search_result(&$variables) {
35   $language_interface = \Drupal::languageManager()->getCurrentLanguage();
36
37   $result = $variables['result'];
38   $variables['url'] = UrlHelper::stripDangerousProtocols($result['link']);
39   $variables['title'] = $result['title'];
40   if (isset($result['language']) && $result['language'] != $language_interface->getId() && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
41     $variables['title_attributes']['lang'] = $result['language'];
42     $variables['content_attributes']['lang'] = $result['language'];
43   }
44
45   $info = [];
46   if (!empty($result['plugin_id'])) {
47     $info['plugin_id'] = $result['plugin_id'];
48   }
49   if (!empty($result['user'])) {
50     $info['user'] = $result['user'];
51   }
52   if (!empty($result['date'])) {
53     $info['date'] = format_date($result['date'], 'short');
54   }
55   if (isset($result['extra']) && is_array($result['extra'])) {
56     $info = array_merge($info, $result['extra']);
57   }
58   // Check for existence. User search does not include snippets.
59   $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
60   // Provide separated and grouped meta information..
61   $variables['info_split'] = $info;
62   $variables['info'] = [
63     '#type' => 'inline_template',
64     '#template' => '{{ info|safe_join(" - ") }}',
65     '#context' => ['info' => $info],
66   ];
67 }