function TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext
Same name and namespace in other branches
- 9 core/modules/ckeditor5/src/Plugin/Validation/Constraint/TextEditorObjectDependentValidatorTrait.php \Drupal\ckeditor5\Plugin\Validation\Constraint\TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext()
- 10 core/modules/ckeditor5/src/Plugin/Validation/Constraint/TextEditorObjectDependentValidatorTrait.php \Drupal\ckeditor5\Plugin\Validation\Constraint\TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext()
Creates a text editor object from the execution context.
Works both for an individual text editor config entity and a pair.
Return value
\Drupal\editor\EditorInterface A text editor object, with the text format pre-populated.
8 calls to TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext()
- CKEditor5MediaAndFilterSettingsInSyncConstraintValidator::validate in core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ CKEditor5MediaAndFilterSettingsInSyncConstraintValidator.php - EnabledConfigurablePluginsConstraintValidator::getConfigurableEnabledDefinitions in core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ EnabledConfigurablePluginsConstraintValidator.php - Gets all configurable CKEditor 5 plugin definitions that are enabled.
- FundamentalCompatibilityConstraintValidator::validate in core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ FundamentalCompatibilityConstraintValidator.php - SourceEditingPreventSelfXssConstraintValidator::validate in core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ SourceEditingPreventSelfXssConstraintValidator.php - SourceEditingRedundantTagsConstraintValidator::validate in core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ SourceEditingRedundantTagsConstraintValidator.php
File
-
core/
modules/ ckeditor5/ src/ Plugin/ Validation/ Constraint/ TextEditorObjectDependentValidatorTrait.php, line 25
Class
- TextEditorObjectDependentValidatorTrait
- Some CKEditor 5 constraint validators need a Text Editor object.
Namespace
Drupal\ckeditor5\Plugin\Validation\ConstraintCode
private function createTextEditorObjectFromContext() : EditorInterface {
if ($this->context
->getRoot()
->getDataDefinition()
->getDataType() === 'ckeditor5_valid_pair__format_and_editor') {
$text_format = FilterFormat::create([
'filters' => $this->context
->getRoot()
->get('filters')
->toArray(),
]);
}
else {
assert(in_array($this->context
->getRoot()
->getDataDefinition()
->getDataType(), [
'editor.editor.*',
'entity:editor',
], TRUE));
$text_format = FilterFormat::load($this->context
->getRoot()
->get('format')
->getValue());
// This validator must not complain about a missing text format.
// @see \Drupal\Tests\editor\Kernel\EditorValidationTest::testInvalidFormat()
if ($text_format === NULL) {
$text_format = FilterFormat::create([]);
}
}
assert($text_format instanceof FilterFormatInterface);
$text_editor = Editor::create([
'editor' => 'ckeditor5',
'settings' => $this->context
->getRoot()
->get('settings')
->toArray(),
'image_upload' => $this->context
->getRoot()
->get('image_upload')
->toArray(),
// Specify `filterFormat` to ensure that the generated Editor config
// entity object already has the $filterFormat property set, to prevent
// calls to Editor::hasAssociatedFilterFormat() and
// Editor::getFilterFormat() from loading the FilterFormat from storage.
// As far as this validation constraint validator is concerned, the
// concrete FilterFormat entity ID does not matter, all that matters is
// its filter configuration. Those exist in $text_format.
'filterFormat' => $text_format,
]);
assert($text_editor instanceof EditorInterface);
return $text_editor;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.