Commit 98348f84 authored by Rajab Natshah's avatar Rajab Natshah 💬
Browse files

Issue #2958532 by R_H-L, RajabNatshah, pookmish: Integration with LinkIt using...

Issue #2958532 by R_H-L, RajabNatshah, pookmish: Integration with LinkIt using an Anchor Link Matcher plugin for LinkIt to use the same drupal link core for CKEditor
parent 2ddba084
Loading
Loading
Loading
Loading
+4 −4
Changes for src/Plugin/CKEditorPlugin/AnchorLink.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -51,12 +51,12 @@ class AnchorLink extends CKEditorPluginBase {
   */
  public function getButtons() {
    return [
      'Link' => [
        'label' => $this->t('Link'),
      'LinkToAnchor' => [
        'label' => $this->t('Link to anchor'),
        'image' => drupal_get_path('module', 'anchor_link') . '/js/plugins/link/icons/link.png',
      ],
      'Unlink' => [
        'label' => $this->t('Unlink'),
      'UnlinkAnchor' => [
        'label' => $this->t('Unlink Anchor'),
        'image' => drupal_get_path('module', 'anchor_link') . '/js/plugins/link/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;
  }

}