You are here

function editor_form_filter_admin_format_submit in Drupal 9

Same name and namespace in other branches
  1. 8 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 242
Adds bindings for client-side "text editors" to text formats.

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);
    }
    $editor
      ->save();
  }
}