You are here

public function FrontPageMatcher::execute in Linkit 8.5

Executes the matcher.

Parameters

string $string: The string that contains the text to search for.

Return value

\Drupal\linkit\Suggestion\SuggestionCollection A suggestion collection.

Overrides MatcherInterface::execute

File

src/Plugin/Linkit/Matcher/FrontPageMatcher.php, line 23

Class

FrontPageMatcher
Provides specific linkit matchers for the front page.

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

public function execute($string) {
  $suggestions = new SuggestionCollection();

  // Special for link to front page.
  if (strpos($string, 'front') !== FALSE) {
    $suggestion = new DescriptionSuggestion();
    $suggestion
      ->setLabel($this
      ->t('Front page'))
      ->setPath(Url::fromRoute('<front>')
      ->toString())
      ->setGroup($this
      ->t('System'))
      ->setDescription($this
      ->t('The front page for this site.'));
    $suggestions
      ->addSuggestion($suggestion);
  }
  return $suggestions;
}