5 * Contains \Drupal\linkit\Plugin\CKEditorPlugin\Linkit.
8 namespace Drupal\linkit\Plugin\CKEditorPlugin;
10 use Drupal\ckeditor\CKEditorPluginBase;
11 use Drupal\ckeditor\CKEditorPluginConfigurableInterface;
12 use Drupal\Core\Entity\EntityStorageInterface;
13 use Drupal\Core\Form\FormStateInterface;
14 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
15 use Drupal\editor\Entity\Editor;
16 use Symfony\Component\DependencyInjection\ContainerInterface;
19 * Defines the "linkit" plugin.
23 * label = @Translation("Linkit"),
27 class Linkit extends CKEditorPluginBase implements CKEditorPluginConfigurableInterface, ContainerFactoryPluginInterface {
30 * The Linkit profile storage.
32 * @var \Drupal\Core\Entity\EntityStorageInterface
34 protected $linkitProfileStorage;
39 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $linkit_profile_storage) {
40 parent::__construct($configuration, $plugin_id, $plugin_definition);
41 $this->linkitProfileStorage = $linkit_profile_storage;
47 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
52 $container->get('entity.manager')->getStorage('linkit_profile')
59 public function getFile() {
60 return drupal_get_path('module', 'linkit') . '/js/plugins/linkit/plugin.js';
66 public function getConfig(Editor $editor) {
68 'linkit_dialogTitleAdd' => t('Add link'),
69 'linkit_dialogTitleEdit' => t('Edit link'),
76 public function getButtons() {
79 'label' => t('Linkit'),
80 'image' => drupal_get_path('module', 'linkit') . '/js/plugins/linkit/linkit.png',
88 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
89 $settings = $editor->getSettings();
91 $all_profiles = $this->linkitProfileStorage->loadMultiple();
94 foreach ($all_profiles as $profile) {
95 $options[$profile->id()] = $profile->label();
98 $form['linkit_profile'] = array(
100 '#title' => t('Select a linkit profile'),
101 '#options' => $options,
102 '#default_value' => isset($settings['plugins']['linkit']) ? $settings['plugins']['linkit'] : '',
103 '#empty_option' => $this->t('- Select profile -'),
104 '#description' => $this->t('Select the linkit profile you wish to use with this text format.'),
105 '#element_validate' => array(
106 array($this, 'validateLinkitProfileSelection'),
114 * #element_validate handler for the "linkit_profile" element in settingsForm().
116 public function validateLinkitProfileSelection(array $element, FormStateInterface $form_state) {
117 $toolbar_buttons = $form_state->getValue(array('editor', 'settings', 'toolbar', 'button_groups'));
118 if (strpos($toolbar_buttons, '"Linkit"') !== FALSE && empty($element['#value'])) {
119 $form_state->setError($element, t('Please select the linkit profile you wish to use.'));