function CKEditor5::getEventualEditorWithPrimedFilterFormat

Same name and namespace in other branches
  1. 9 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::getEventualEditorWithPrimedFilterFormat()
  2. 10 core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php \Drupal\ckeditor5\Plugin\Editor\CKEditor5::getEventualEditorWithPrimedFilterFormat()

Gets the eventual text format config entity: from form state + editor.

Needed for validation.

Parameters

\Drupal\Core\Form\SubformStateInterface $editor_form_state: The text editor configuration form's form state.

\Drupal\editor\EditorInterface $submitted_editor: The current text editor config entity.

Return value

\Drupal\editor\EditorInterface A clone of the received Editor config entity , with a primed associated FilterFormat that corresponds to the current form state, to avoid the stored FilterFormat config entity being loaded.

3 calls to CKEditor5::getEventualEditorWithPrimedFilterFormat()
CKEditor5::buildConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form constructor.
CKEditor5::injectPluginSettingsForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Injects the CKEditor plugins settings forms as a vertical tabs subform.
CKEditor5::validateConfigurationForm in core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php
Form validation handler.

File

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

Class

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

Namespace

Drupal\ckeditor5\Plugin\Editor

Code

protected function getEventualEditorWithPrimedFilterFormat(SubformStateInterface $editor_form_state, EditorInterface $submitted_editor) : EditorInterface {
  $submitted_filter_format = static::getSubmittedFilterFormat($editor_form_state->getCompleteFormState());
  $pair = static::createEphemeralPairedEditor($submitted_editor, $submitted_filter_format);
  // When CKEditor 5 plugins are disabled in the form-based admin UI, the
  // associated settings (if any) should be omitted too, except for plugins
  // that are enabled using `requiresConfiguration` (because whether they are
  // enabled or not depends on the associated settings).
  $original_settings = $pair->getSettings();
  $enabled_plugins = $this->ckeditor5PluginManager
    ->getEnabledDefinitions($pair);
  $config_enabled_plugins = [];
  foreach ($this->ckeditor5PluginManager
    ->getDefinitions() as $id => $definition) {
    if ($definition->hasConditions() && isset($definition->getConditions()['requiresConfiguration'])) {
      $config_enabled_plugins[$id] = TRUE;
    }
  }
  $updated_settings = [
    'plugins' => array_intersect_key($original_settings['plugins'], $enabled_plugins + $config_enabled_plugins),
  ] + $original_settings;
  $pair->setSettings($updated_settings);
  if ($pair->getFilterFormat()
    ->filters('filter_html')->status) {
    // Compute elements provided by the current CKEditor 5 settings.
    $restrictions = new HTMLRestrictions($this->ckeditor5PluginManager
      ->getProvidedElements(array_keys($enabled_plugins), $pair));
    // Compute eventual filter_html setting. Eventual as in: this is the list
    // of eventually allowed HTML tags.
    // @see \Drupal\filter\FilterFormatFormBase::submitForm()
    // @see ckeditor5_form_filter_format_form_alter()
    $filter_html_config = $pair->getFilterFormat()
      ->filters('filter_html')
      ->getConfiguration();
    $filter_html_config['settings']['allowed_html'] = $restrictions->toFilterHtmlAllowedTagsString();
    $pair->getFilterFormat()
      ->setFilterConfig('filter_html', $filter_html_config);
  }
  return $pair;
}

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