You are here

function editor_form_filter_admin_format_submit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 'filter_format_form'.

File

core/modules/editor/editor.module, line 219
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(array(
    'editor',
    'editor',
  ))) {
    $original_editor
      ->delete();
  }

  // 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);
    $editor
      ->setSettings($form_state
      ->getValue([
      'editor',
      'settings',
    ]));
    $editor
      ->save();
  }
}