function ckeditor5_filter_format_edit_form_submit
Same name in other branches
- 9 core/modules/ckeditor5/ckeditor5.module \ckeditor5_filter_format_edit_form_submit()
- 11.x core/modules/ckeditor5/ckeditor5.module \ckeditor5_filter_format_edit_form_submit()
Form submission handler for filter format forms.
1 string reference to 'ckeditor5_filter_format_edit_form_submit'
- ckeditor5_form_filter_format_form_alter in core/
modules/ ckeditor5/ ckeditor5.module - Implements hook_form_FORM_ID_alter().
File
-
core/
modules/ ckeditor5/ ckeditor5.module, line 236
Code
function ckeditor5_filter_format_edit_form_submit(array $form, FormStateInterface $form_state) {
$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.