Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / linkit / src / ResultManager.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\linkit\ResultManager.
6  */
7
8 namespace Drupal\linkit;
9
10
11 use Drupal\Component\Utility\Html;
12 use Drupal\Core\Url;
13
14 /**
15  * Result service to handle autocomplete matcher results.
16  */
17 class ResultManager {
18
19   /**
20    * Gets the results.
21    *
22    * @param ProfileInterface $linkitProfile
23    *   The linkit profile.
24    * @param $search_string
25    *   The string ro use in the matchers.
26    *
27    * @return array
28    *   An array of matches.
29    */
30   public function getResults(ProfileInterface $linkitProfile, $search_string) {
31     $matches = array();
32
33     if (empty(trim($search_string))) {
34       return [[
35         'title' => t('No results'),
36       ]];
37     }
38
39     // Special for link to front page.
40     if (strpos($search_string, 'front') !== FALSE) {
41       $matches[] = [
42         'title' => t('Front page'),
43         'description' => 'The front page for this site.',
44         'path' => Url::fromRoute('<front>')->toString(),
45         'group' => t('System'),
46       ];
47     }
48
49     foreach ($linkitProfile->getMatchers() as $plugin) {
50       $matches = array_merge($matches, $plugin->getMatches($search_string));
51     }
52
53     // Check for an e-mail address then return an e-mail match and create a
54     // mail-to link if appropriate.
55     if (filter_var($search_string, FILTER_VALIDATE_EMAIL)) {
56       $matches[] = [
57         'title' => t('E-mail @email', ['@email' => $search_string]),
58         'description' => t('Opens your mail client ready to e-mail @email', ['@email' => $search_string]),
59         'path' => 'mailto:' . Html::escape($search_string),
60         'group' => t('E-mail'),
61       ];
62     }
63
64     // If there is still no matches, return a "no results" array.
65     if (empty($matches)) {
66       return [[
67         'title' => t('No results'),
68       ]];
69     }
70
71     return $matches;
72   }
73
74 }