You are here

public function EmailMatcher::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/EmailMatcher.php, line 23

Class

EmailMatcher
Provides specific linkit matchers for emails.

Namespace

Drupal\linkit\Plugin\Linkit\Matcher

Code

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

  // Check for an e-mail address then return an e-mail match and create a
  // mail-to link if appropriate.
  if (filter_var($string, FILTER_VALIDATE_EMAIL)) {
    $suggestion = new DescriptionSuggestion();
    $suggestion
      ->setLabel($this
      ->t('E-mail @email', [
      '@email' => $string,
    ]))
      ->setPath('mailto:' . Html::escape($string))
      ->setGroup($this
      ->t('E-mail'))
      ->setDescription($this
      ->t('Opens your mail client ready to e-mail @email', [
      '@email' => $string,
    ]));
    $suggestions
      ->addSuggestion($suggestion);
  }
  return $suggestions;
}