function Ckeditor5Hooks::filterFormatEditFormSubmit
Same name and namespace in other branches
- main core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php \Drupal\ckeditor5\Hook\Ckeditor5Hooks::filterFormatEditFormSubmit()
Form submission handler for filter format forms.
Parameters
array $form: The form render array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
File
-
core/
modules/ ckeditor5/ src/ Hook/ Ckeditor5Hooks.php, line 487
Class
- Ckeditor5Hooks
- Hook implementations for ckeditor5.
Namespace
Drupal\ckeditor5\HookCode
public function filterFormatEditFormSubmit(array $form, FormStateInterface $form_state) : void {
$limit_allowed_html_tags = isset($form['filters']['settings']['filter_html']['allowed_html']);
$manually_editable_tags = $form_state->getValue([
'editor',
'settings',
'plugins',
'ckeditor5_sourceEditing',
'allowed_tags',
]);
$styles = $form_state->getValue([
'editor',
'settings',
'plugins',
'ckeditor5_style',
'styles',
]);
if ($limit_allowed_html_tags && is_array($manually_editable_tags) || is_array($styles)) {
// When "Manually editable tags", "Style" and "limit allowed HTML tags"
// are all configured, the latter is dependent on the others. This
// dependent value is typically updated via AJAX, but it's possible for
// "Manually editable tags" to update without triggering the AJAX rebuild.
// That value is recalculated here on save to ensure it happens even if
// the AJAX rebuild doesn't happen.
$manually_editable_tags_restrictions = HTMLRestrictions::fromString(implode($manually_editable_tags ?? []));
$styles_restrictions = HTMLRestrictions::fromString(implode($styles ? array_column($styles, 'element') : []));
$format = $form_state->get('ckeditor5_validated_pair')
->getFilterFormat();
$allowed_html = HTMLRestrictions::fromTextFormat($format);
$combined_tags_string = $allowed_html->merge($manually_editable_tags_restrictions)
->merge($styles_restrictions)
->toFilterHtmlAllowedTagsString();
$form_state->setValue([
'filters',
'filter_html',
'settings',
'allowed_html',
], $combined_tags_string);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.