function editor_form_filter_admin_format_submit

Same name in other branches
  1. 9 core/modules/editor/editor.module \editor_form_filter_admin_format_submit()
  2. 8.9.x core/modules/editor/editor.module \editor_form_filter_admin_format_submit()
  3. 10 core/modules/editor/editor.module \editor_form_filter_admin_format_submit()

Additional submit handler for filter_format_form().

1 string reference to 'editor_form_filter_admin_format_submit'
editor_form_filter_format_form_alter in core/modules/editor/editor.module
Implements hook_form_BASE_FORM_ID_alter() for \Drupal\filter\FilterFormatEditForm.

File

core/modules/editor/editor.module, line 229

Code

function editor_form_filter_admin_format_submit($form, FormStateInterface $form_state) {
    // Delete the existing editor if disabling or switching between editors.
    $format = $form_state->getFormObject()
        ->getEntity();
    $format_id = $format->isNew() ? NULL : $format->id();
    $original_editor = editor_load($format_id);
    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.