CKEditorAnchorLinkMatcher.php in CKEditor Anchor Link - For Drupal 8 and 9 3.0.x
File
src/Plugin/Linkit/Matcher/CKEditorAnchorLinkMatcher.php
View source
<?php
namespace Drupal\anchor_link\Plugin\Linkit\Matcher;
use Drupal\Component\Utility\Html;
use Drupal\linkit\MatcherBase;
use Drupal\linkit\Suggestion\DescriptionSuggestion;
use Drupal\linkit\Suggestion\SuggestionCollection;
class CKEditorAnchorLinkMatcher extends MatcherBase {
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;
}
}