5 * Contains \Drupal\linkit\ResultManager.
8 namespace Drupal\linkit;
11 use Drupal\Component\Utility\Html;
15 * Result service to handle autocomplete matcher results.
22 * @param ProfileInterface $linkitProfile
24 * @param $search_string
25 * The string ro use in the matchers.
28 * An array of matches.
30 public function getResults(ProfileInterface $linkitProfile, $search_string) {
33 if (empty(trim($search_string))) {
35 'title' => t('No results'),
39 // Special for link to front page.
40 if (strpos($search_string, 'front') !== FALSE) {
42 'title' => t('Front page'),
43 'description' => 'The front page for this site.',
44 'path' => Url::fromRoute('<front>')->toString(),
45 'group' => t('System'),
49 foreach ($linkitProfile->getMatchers() as $plugin) {
50 $matches = array_merge($matches, $plugin->getMatches($search_string));
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)) {
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'),
64 // If there is still no matches, return a "no results" array.
65 if (empty($matches)) {
67 'title' => t('No results'),