class Alignment
Same name and namespace in other branches
- 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Alignment.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment
- 11.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Alignment.php \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment
CKEditor 5 Alignment plugin.
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault extends \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Alignment extends \Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableInterface, \Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface uses \Drupal\ckeditor5\Plugin\CKEditor5PluginConfigurableTrait implements \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault
- class \Drupal\ckeditor5\Plugin\CKEditor5PluginDefault extends \Drupal\ckeditor5\Plugin\CKEditor5PluginInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of Alignment
1 file declares its use of Alignment
- AlignmentPluginTest.php in core/
modules/ ckeditor5/ tests/ src/ Unit/ AlignmentPluginTest.php
12 string references to 'Alignment'
- ckeditor5.ckeditor5.yml in core/
modules/ ckeditor5/ ckeditor5.ckeditor5.yml - core/modules/ckeditor5/ckeditor5.ckeditor5.yml
- ckeditor5.ckeditor5.yml in core/
modules/ ckeditor5/ ckeditor5.ckeditor5.yml - core/modules/ckeditor5/ckeditor5.ckeditor5.yml
- CKEditor5PluginManagerTest::testEnabledPlugins in core/
modules/ ckeditor5/ tests/ src/ Kernel/ CKEditor5PluginManagerTest.php - Tests the enabling of plugins.
- Core::mapCKEditor4ToolbarButtonToCKEditor5ToolbarItem in core/
modules/ ckeditor5/ src/ Plugin/ CKEditor4To5Upgrade/ Core.php - Maps a CKEditor 4 button to the CKEditor 5 equivalent, if it exists.
- Grid::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ style/ Grid.php - Provide a form to edit options for this plugin.
File
-
core/
modules/ ckeditor5/ src/ Plugin/ CKEditor5Plugin/ Alignment.php, line 21
Namespace
Drupal\ckeditor5\Plugin\CKEditor5PluginView source
class Alignment extends CKEditor5PluginDefault implements CKEditor5PluginConfigurableInterface, CKEditor5PluginElementsSubsetInterface {
use CKEditor5PluginConfigurableTrait;
/**
* The default configuration for this plugin.
*
* @var string[][]
*/
const DEFAULT_CONFIGURATION = [
'enabled_alignments' => [
'left',
'center',
'right',
'justify',
],
];
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return static::DEFAULT_CONFIGURATION;
}
/**
* {@inheritdoc}
*
* Form for choosing which alignment types are available.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['enabled_alignments'] = [
'#type' => 'fieldset',
'#title' => $this->t('Enabled Alignments'),
'#description' => $this->t('These are the alignment types that will appear in the alignment dropdown.'),
];
foreach ($this->getPluginDefinition()
->getCKEditor5Config()['alignment']['options'] as $alignment_option) {
$name = $alignment_option['name'];
$form['enabled_alignments'][$name] = [
'#type' => 'checkbox',
'#title' => $this->t($name),
'#return_value' => $name,
'#default_value' => in_array($name, $this->configuration['enabled_alignments'], TRUE) ? $name : NULL,
];
}
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Match the config schema structure at ckeditor5.plugin.ckeditor5_alignment.
$form_value = $form_state->getValue('enabled_alignments');
$config_value = array_values(array_filter($form_value));
$form_state->setValue('enabled_alignments', $config_value);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['enabled_alignments'] = $form_state->getValue('enabled_alignments');
}
/**
* {@inheritdoc}
*
* Filters the alignment options to those chosen in editor config.
*/
public function getDynamicPluginConfig(array $static_plugin_config, EditorInterface $editor) : array {
$enabled_alignments = $this->configuration['enabled_alignments'];
$all_alignment_options = $static_plugin_config['alignment']['options'];
$configured_alignment_options = array_filter($all_alignment_options, function ($option) use ($enabled_alignments) {
return in_array($option['name'], $enabled_alignments, TRUE);
});
return [
'alignment' => [
'options' => array_values($configured_alignment_options),
],
];
}
/**
* {@inheritdoc}
*/
public function getElementsSubset() : array {
$enabled_alignments = $this->configuration['enabled_alignments'];
$plugin_definition = $this->getPluginDefinition();
$all_elements = $plugin_definition->getElements();
$subset = HTMLRestrictions::fromString(implode($all_elements));
foreach ($plugin_definition->getCKEditor5Config()['alignment']['options'] as $configured_alignment) {
if (!in_array($configured_alignment['name'], $enabled_alignments, TRUE)) {
$element_string = '<$text-container class=' . '"' . $configured_alignment["className"] . '"' . '>';
$subset = $subset->diff(HTMLRestrictions::fromString($element_string));
}
}
return $subset->toCKEditor5ElementsArray();
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Alignment::buildConfigurationForm | public | function | Form for choosing which alignment types are available. | Overrides PluginFormInterface::buildConfigurationForm | |
Alignment::defaultConfiguration | public | function | Gets default configuration for this plugin. | Overrides ConfigurableInterface::defaultConfiguration | |
Alignment::DEFAULT_CONFIGURATION | constant | The default configuration for this plugin. | |||
Alignment::getDynamicPluginConfig | public | function | Filters the alignment options to those chosen in editor config. | Overrides CKEditor5PluginDefault::getDynamicPluginConfig | |
Alignment::getElementsSubset | public | function | Returns a configured subset of the elements supported by this plugin. | Overrides CKEditor5PluginElementsSubsetInterface::getElementsSubset | |
Alignment::submitConfigurationForm | public | function | Form submission handler. | Overrides PluginFormInterface::submitConfigurationForm | |
Alignment::validateConfigurationForm | public | function | Form validation handler. | Overrides PluginFormInterface::validateConfigurationForm | |
CKEditor5PluginConfigurableTrait::getConfiguration | public | function | |||
CKEditor5PluginConfigurableTrait::setConfiguration | public | function | |||
CKEditor5PluginDefault::__construct | public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | Overrides PluginBase::__construct | 3 |
DependencySerializationTrait::$_entityStorages | protected | property | An array of entity type IDs keyed by the property name of their storages. | ||
DependencySerializationTrait::$_serviceIds | protected | property | An array of service IDs keyed by property name used for serialization. | ||
DependencySerializationTrait::__sleep | public | function | 2 | ||
DependencySerializationTrait::__wakeup | public | function | #[\ReturnTypeWillChange] | 2 | |
MessengerTrait::$messenger | protected | property | The messenger. | 25 | |
MessengerTrait::messenger | public | function | Gets the messenger. | 25 | |
MessengerTrait::setMessenger | public | function | Sets the messenger. | ||
PluginBase::$configuration | protected | property | Configuration information passed into the plugin. | 1 | |
PluginBase::$pluginDefinition | protected | property | The plugin implementation definition. | 1 | |
PluginBase::$pluginId | protected | property | The plugin ID. | ||
PluginBase::DERIVATIVE_SEPARATOR | constant | A string which is used to separate base plugin IDs from the derivative ID. | |||
PluginBase::getBaseId | public | function | Gets the base_plugin_id of the plugin instance. | Overrides DerivativeInspectionInterface::getBaseId | |
PluginBase::getDerivativeId | public | function | Gets the derivative_id of the plugin instance. | Overrides DerivativeInspectionInterface::getDerivativeId | |
PluginBase::getPluginDefinition | public | function | Gets the definition of the plugin implementation. | Overrides PluginInspectionInterface::getPluginDefinition | 2 |
PluginBase::getPluginId | public | function | Gets the plugin ID of the plugin instance. | Overrides PluginInspectionInterface::getPluginId | |
PluginBase::isConfigurable | public | function | Determines if the plugin is configurable. | ||
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.