protected function CKEditor5::getEventualEditorWithPrimedFilterFormat in Drupal 10
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.
File
- core/
modules/ ckeditor5/ src/ Plugin/ Editor/ CKEditor5.php, line 784
Class
- CKEditor5
- Defines a CKEditor 5-based text editor for Drupal.
Namespace
Drupal\ckeditor5\Plugin\EditorCode
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;
}