function EditorHooks::editorFormFilterAdminFormatSubmit
Same name and namespace in other branches
- main core/modules/editor/src/Hook/EditorHooks.php \Drupal\editor\Hook\EditorHooks::editorFormFilterAdminFormatSubmit()
Additional submit handler for 'filter_format_form' form.
Parameters
array $form: The form render array.
\Drupal\Core\Form\FormStateInterface $form_state: The current form state.
File
-
core/
modules/ editor/ src/ Hook/ EditorHooks.php, line 569
Class
- EditorHooks
- Hook implementations for editor.
Namespace
Drupal\editor\HookCode
public function editorFormFilterAdminFormatSubmit(array $form, FormStateInterface $form_state) : void {
// Delete the existing editor if disabling or switching between editors.
$format = $form_state->getFormObject()
->getEntity();
$format_id = $format->isNew() ? NULL : $format->id();
$original_editor = $format_id ? Editor::load($format_id) : NULL;
if ($original_editor && $original_editor->getEditor() != $form_state->getValue([
'editor',
'editor',
])) {
$original_editor->delete();
}
$editor_set = $form_state->getValue([
'editor',
'editor',
]) !== "";
$subform_array_exists = !empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform']);
if (($editor_plugin = $form_state->get('editor_plugin')) && $editor_set && $subform_array_exists) {
$subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state);
$editor_plugin->submitConfigurationForm($form['editor']['settings']['subform'], $subform_state);
}
// Create a new editor or update the existing editor.
if ($editor = $form_state->get('editor')) {
// Ensure the text format is set: when creating a new text format, this
// would equal the empty string.
$editor->set('format', $format_id);
if ($settings = $form_state->getValue([
'editor',
'settings',
])) {
$editor->setSettings($settings);
}
// When image uploads are disabled (status = FALSE), the schema for image
// upload settings does not allow other keys to be present.
// @see editor.image_upload_settings.*
// @see editor.image_upload_settings.1
// @see editor.schema.yml
$image_upload_settings = $editor->getImageUploadSettings();
if (!$image_upload_settings['status']) {
$editor->setImageUploadSettings([
'status' => FALSE,
]);
}
$editor->save();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.