function CKEditor5::createEphemeralPairedEditor

Same name in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::createEphemeralPairedEditor()
  2. 11.x core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::createEphemeralPairedEditor()

Creates an ephemeral pair of text editor + text format config entity.

Clones the given text editor config entity object and then overwrites its $filterFormat property, to prevent loading the text format config entity from entity storage in calls to Editor::hasAssociatedFilterFormat() and Editor::getFilterFormat(). This is necessary to be able to evaluate unsaved text editor and format config entities:

  • for assessing which CKEditor 5 plugins are enabled and whose settings forms to show
  • for validating them.

@todo Remove this in https://www.drupal.org/project/drupal/issues/3231347

Parameters

\Drupal\editor\EditorInterface $editor: The submitted text editor config entity, constructed from form values.

\Drupal\filter\FilterFormatInterface $filter_format: The submitted text format config entity, constructed from form values.

Return value

\Drupal\editor\EditorInterface A clone of the given text editor config entity, with its $filterFormat property set to a clone of the given text format config entity.

Throws

\ReflectionException

See also

\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::isPluginDisabled()

1 call to CKEditor5::createEphemeralPairedEditor()
CKEditor5::getEventualEditorWithPrimedFilterFormat in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Gets the eventual text format config entity: from form state + editor.

File

core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php, line 847

Class

CKEditor5
Defines a CKEditor 5-based text editor for Drupal.

Namespace

Drupal\ckeditor5\Plugin\Editor

Code

protected static function createEphemeralPairedEditor(EditorInterface $editor, FilterFormatInterface $filter_format) : EditorInterface {
    $paired_editor = clone $editor;
    // If the editor is still being configured, the configuration may not yet be
    // valid. Explicitly mark the ephemeral paired editor as new to allow other
    // code to treat this accordingly.
    // @see \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements()
    $paired_editor->enforceIsNew(TRUE);
    $reflector = new \ReflectionObject($paired_editor);
    $property = $reflector->getProperty('filterFormat');
    $property->setValue($paired_editor, clone $filter_format);
    return $paired_editor;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.