function CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::validate
Same name in other branches
- 10 core/modules/ckeditor5/src/Plugin/Validation/Constraint/CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::validate()
- 11.x core/modules/ckeditor5/src/Plugin/Validation/Constraint/CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::validate()
Throws
\Symfony\Component\Validator\Exception\UnexpectedTypeException Thrown when the given constraint is not supported by this validator.
File
-
core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php, line 70
Class
- CKEditor5MediaAndFilterSettingsInSyncConstraintValidator
- CKEditor 5 Media plugin in sync with the filter settings validator.
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintCode
public function validate($toolbar_item, Constraint $constraint) {
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,
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.