You are here

private function TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext in Drupal 10

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.

7 calls to TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext()
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
StyleSensibleElementConstraintValidator::findStyleConflictingPluginLabel in core/modules/ckeditor5/src/Plugin/Validation/Constraint/StyleSensibleElementConstraintValidator.php
Finds the plugin with elements that conflict with the style element.

... See full list

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\Constraint

Code

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($this->context
      ->getRoot()
      ->getDataDefinition()
      ->getDataType() === 'editor.editor.*');
    $text_format = FilterFormat::load($this->context
      ->getRoot()
      ->get('format')
      ->getValue());
  }
  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;
}