Commit 1e948d61 authored by Rajab Natshah's avatar Rajab Natshah 💬
Browse files

Issue #2958532: Integration with LinkIt using an Anchor Link Matcher plugin...

Issue #2958532: Integration with LinkIt using an Anchor Link Matcher plugin for LinkIt to use the same drupal link core for CKEditor
parent 454126cb
Loading
Loading
Loading
Loading
+3 −3
Changes for src/Plugin/CKEditorPlugin/AnchorLink.php: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -53,12 +53,12 @@ class AnchorLink extends CKEditorPluginBase {
    $libraryUrl = $this->getLibraryUrl();

    return [
      'Link' => [
        'label' => $this->t('Link'),
      'LinkToAnchor' => [
        'label' => $this->t('Link to anchor'),
        'image' => $libraryUrl . '/icons/link.png',
      ],
      'Unlink' => [
        'label' => $this->t('Unlink'),
        'label' => $this->t('Unlink anchor'),
        'image' => $libraryUrl . '/icons/unlink.png',
      ],
      'Anchor' => [
+38 −0
Changes for src/Plugin/Linkit/Matcher/CKEditorAnchorLinkMatcher.php: 38 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?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;

/**
 * Provides specific linkit matchers for Anchor links.
 *
 * @Matcher(
 *   id = "ckeditor_anchor_link",
 *   label = @Translation("CKEditor Anchor link"),
 * )
 */
class CKEditorAnchorLinkMatcher extends MatcherBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

}