class LinkitDrupalLink in Linkit 8.5
Adds a settings form to select a Linkit profile on the default link plugin.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink
- class \Drupal\linkit\Plugin\CKEditorPlugin\LinkitDrupalLink implements CKEditorPluginConfigurableInterface, ContainerFactoryPluginInterface
- class \Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalLink
- class \Drupal\ckeditor\CKEditorPluginBase implements CKEditorPluginButtonsInterface, CKEditorPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of LinkitDrupalLink
File
- src/
Plugin/ CKEditorPlugin/ LinkitDrupalLink.php, line 16
Namespace
Drupal\linkit\Plugin\CKEditorPluginView source
class LinkitDrupalLink extends DrupalLink implements CKEditorPluginConfigurableInterface, ContainerFactoryPluginInterface {
/**
* The Linkit profile storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $linkitProfileStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityStorageInterface $linkit_profile_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->linkitProfileStorage = $linkit_profile_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager')
->getStorage('linkit_profile'));
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
$settings = $editor
->getSettings();
$all_profiles = $this->linkitProfileStorage
->loadMultiple();
$options = [];
foreach ($all_profiles as $profile) {
$options[$profile
->id()] = $profile
->label();
}
$form['linkit_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Linkit enabled'),
'#default_value' => isset($settings['plugins']['drupallink']['linkit_enabled']) ? $settings['plugins']['drupallink']['linkit_enabled'] : '',
'#description' => $this
->t('Enable Linkit for this text format.'),
];
$form['linkit_profile'] = [
'#type' => 'select',
'#title' => $this
->t('Linkit profile'),
'#options' => $options,
'#default_value' => isset($settings['plugins']['drupallink']['linkit_profile']) ? $settings['plugins']['drupallink']['linkit_profile'] : '',
'#empty_option' => $this
->t('- Select -'),
'#description' => $this
->t('Select the Linkit profile you wish to use with this text format.'),
'#states' => [
'invisible' => [
'input[data-drupal-selector="edit-editor-settings-plugins-drupallink-linkit-enabled"]' => [
'checked' => FALSE,
],
],
],
'#element_validate' => [
[
$this,
'validateLinkitProfileSelection',
],
],
];
return $form;
}
/**
* Linkit profile select validation.
*
* #element_validate callback for the "linkit_profile" element.
*
* @param array $element
* An associative array containing the properties and children of the
* generic form element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form for the form this element belongs to.
*
* @see \Drupal\Core\Render\Element\FormElement::processPattern()
*/
public function validateLinkitProfileSelection(array $element, FormStateInterface $form_state) {
$values = $form_state
->getValue([
'editor',
'settings',
'plugins',
'drupallink',
]);
$enabled = isset($values['linkit_enabled']) && $values['linkit_enabled'] === 1;
if ($enabled && empty(trim($values['linkit_profile']))) {
$form_state
->setError($element, $this
->t('Please select the Linkit profile you wish to use.'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CKEditorPluginBase:: |
public | function |
Returns a list of plugins this plugin requires. Overrides CKEditorPluginInterface:: |
1 |
CKEditorPluginBase:: |
public | function |
Indicates if this plugin is part of the optimized CKEditor build. Overrides CKEditorPluginInterface:: |
4 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DrupalLink:: |
public | function |
Returns the buttons that this plugin provides, along with metadata. Overrides CKEditorPluginButtonsInterface:: |
|
DrupalLink:: |
public | function |
Returns the additions to CKEDITOR.config for a specific CKEditor instance. Overrides CKEditorPluginInterface:: |
|
DrupalLink:: |
public | function |
Returns the Drupal root-relative file path to the plugin JavaScript file. Overrides CKEditorPluginInterface:: |
|
DrupalLink:: |
public | function |
Returns a list of libraries this plugin requires. Overrides CKEditorPluginBase:: |
|
LinkitDrupalLink:: |
protected | property | The Linkit profile storage. | |
LinkitDrupalLink:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
LinkitDrupalLink:: |
public | function |
Returns a settings form to configure this CKEditor plugin. Overrides CKEditorPluginConfigurableInterface:: |
|
LinkitDrupalLink:: |
public | function | Linkit profile select validation. | |
LinkitDrupalLink:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |