You are here

public function CKEditorAnchorLinkMatcher::execute in CKEditor Anchor Link - For Drupal 8 and 9 3.0.x

File

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

Class

CKEditorAnchorLinkMatcher
Provides specific linkit matchers for Anchor links.

Namespace

Drupal\anchor_link\Plugin\Linkit\Matcher

Code

public function execute($string) {
  $suggestions = new SuggestionCollection();
  $string = ltrim($string, '#');
  $suggestion = new DescriptionSuggestion();
  $suggestion
    ->setLabel($this
    ->t('#@anchor_link', [
    '@anchor_link' => $string,
  ]))
    ->setPath('#' . $string)
    ->setGroup($this
    ->t('Anchor links (within the same page)'));
  $suggestions
    ->addSuggestion($suggestion);
  return $suggestions;
}