class CKEditor5MediaAndFilterSettingsInSyncConstraintValidator
Same name in other branches
- 9 core/modules/ckeditor5/src/Plugin/Validation/Constraint/CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5MediaAndFilterSettingsInSyncConstraintValidator
- 10 core/modules/ckeditor5/src/Plugin/Validation/Constraint/CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5MediaAndFilterSettingsInSyncConstraintValidator
CKEditor 5 Media plugin in sync with the filter settings validator.
@internal
Hierarchy
- class \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5MediaAndFilterSettingsInSyncConstraintValidator extends \Symfony\Component\Validator\ConstraintValidator implements \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\ckeditor5\Plugin\Validation\Constraint\PluginManagerDependentValidatorTrait, \Drupal\ckeditor5\Plugin\Validation\Constraint\TextEditorObjectDependentValidatorTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of CKEditor5MediaAndFilterSettingsInSyncConstraintValidator
File
-
core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php, line 21
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintView source
class CKEditor5MediaAndFilterSettingsInSyncConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
use PluginManagerDependentValidatorTrait;
use TextEditorObjectDependentValidatorTrait;
use StringTranslationTrait;
/**
* The filter plugin manager service.
*
* @var \Drupal\filter\FilterPluginManager
*/
protected $filterPluginManager;
/**
* The typed config manager service.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
/**
* Constructs a new CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.
*
* @param \Drupal\filter\FilterPluginManager $filter_plugin_manager
* The filter plugin manager service.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* The typed config manager service.
*/
public function __construct(FilterPluginManager $filter_plugin_manager, TypedConfigManagerInterface $typed_config_manager) {
$this->filterPluginManager = $filter_plugin_manager;
$this->typedConfigManager = $typed_config_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('plugin.manager.filter'), $container->get('config.typed'));
}
/**
* {@inheritdoc}
*
* @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
* Thrown when the given constraint is not supported by this validator.
*/
public function validate($toolbar_item, Constraint $constraint) : void {
if (!$constraint instanceof CKEditor5MediaAndFilterSettingsInSyncConstraint) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\CKEditor5MediaAndFilterSettingsInSync');
}
$text_editor = $this->createTextEditorObjectFromContext();
if (isset($text_editor->getSettings()['plugins']['media_media'])) {
$cke5_plugin_overrides_allowed = $text_editor->getSettings()['plugins']['media_media']['allow_view_mode_override'];
$filter_allowed_view_modes = $text_editor->getFilterFormat()
->filters('media_embed')
->getConfiguration()['settings']['allowed_view_modes'];
$filter_media_plugin_label = $this->filterPluginManager
->getDefinition('media_embed')['title']
->render();
$filter_media_allowed_view_modes_label = $this->typedConfigManager
->getDefinition('filter_settings.media_embed')['mapping']['allowed_view_modes']['label'];
// Whenever the CKEditor 5 plugin is configured to allow overrides, the
// filter must be configured to allow 2 or more view modes.
if ($cke5_plugin_overrides_allowed && count($filter_allowed_view_modes) < 2) {
$this->context
->addViolation($constraint->message, [
'%cke5_media_plugin_label' => $this->t('Media'),
'%cke5_allow_view_mode_override_label' => $this->t('Allow the user to override the default view mode'),
'%filter_media_plugin_label' => $filter_media_plugin_label,
'%filter_media_allowed_view_modes_label' => $filter_media_allowed_view_modes_label,
]);
}
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::$filterPluginManager | protected | property | The filter plugin manager service. | ||
CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::$typedConfigManager | protected | property | The typed config manager service. | ||
CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::create | public static | function | Instantiates a new instance of this class. | Overrides PluginManagerDependentValidatorTrait::create | |
CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::validate | public | function | |||
CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::__construct | public | function | Constructs a new CKEditor5MediaAndFilterSettingsInSyncConstraintValidator. | Overrides PluginManagerDependentValidatorTrait::__construct | |
PluginManagerDependentValidatorTrait::$pluginManager | protected | property | The CKEditor 5 plugin manager. | ||
PluginManagerDependentValidatorTrait::getEnableableDisabledPlugins | private | function | Gets all disabled CKEditor 5 plugin definitions the user can enable. | ||
PluginManagerDependentValidatorTrait::getOtherEnabledPlugins | private | function | Gets all other enabled CKEditor 5 plugin definitions. | ||
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. | ||
TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext | private | function | Creates a text editor object from the execution context. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.