function editor_form_filter_admin_format_form_alter

Implements hook_form_FORM_ID_alter().

File

drupal/core/modules/editor/editor.module, line 149
Adds bindings for client-side "text editors" to text formats.

Code

function editor_form_filter_admin_format_form_alter(&$form, &$form_state) {
  if (!isset($form_state['editor'])) {
    $format_id = $form['#format']->format;
    $form_state['editor'] = editor_load($format_id);
    $form_state['editor_manager'] = drupal_container()
      ->get('plugin.manager.editor');
  }
  $editor = $form_state['editor'];
  $manager = $form_state['editor_manager'];

  // Associate a text editor with this text format.
  $editor_options = $manager
    ->listOptions();
  $form['editor'] = array(
    // Position the editor selection before the filter settings (weight of 0),
    // but after the filter label and name (weight of -20).
    '#weight' => -9,
  );
  $form['editor']['editor'] = array(
    '#type' => 'select',
    '#title' => t('Text editor'),
    '#options' => $editor_options,
    '#empty_option' => t('None'),
    '#default_value' => $editor ? $editor->editor : '',
    '#ajax' => array(
      'trigger_as' => array(
        'name' => 'editor_configure',
      ),
      'callback' => 'editor_form_filter_admin_form_ajax',
      'wrapper' => 'editor-settings-wrapper',
    ),
    '#weight' => -10,
  );
  $form['editor']['configure'] = array(
    '#type' => 'submit',
    '#name' => 'editor_configure',
    '#value' => t('Configure'),
    '#limit_validation_errors' => array(
      array(
        'editor',
      ),
    ),
    '#submit' => array(
      'editor_form_filter_admin_format_editor_configure',
    ),
    '#ajax' => array(
      'callback' => 'editor_form_filter_admin_form_ajax',
      'wrapper' => 'editor-settings-wrapper',
    ),
    '#weight' => -10,
    '#attributes' => array(
      'class' => array(
        'js-hide',
      ),
    ),
  );

  // If there aren't any options (other than "None"), disable the select list.
  if (empty($editor_options)) {
    $form['editor']['editor']['#disabled'] = TRUE;
    $form['editor']['editor']['#description'] = t('This option is disabled because no modules that provide a text editor are currently enabled.');
  }
  $form['editor']['settings'] = array(
    '#tree' => TRUE,
    '#weight' => -8,
    '#type' => 'container',
    '#id' => 'editor-settings-wrapper',
  );

  // Add editor-specific validation and submit handlers.
  if ($editor) {
    $plugin = $manager
      ->createInstance($editor->editor);
    $settings_form = array();
    $settings_form['#element_validate'][] = array(
      $plugin,
      'settingsFormValidate',
    );
    $form['editor']['settings']['subform'] = $plugin
      ->settingsForm($settings_form, $form_state, $editor);
    $form['editor']['settings']['subform']['#parents'] = array(
      'editor',
      'settings',
    );
    $form['#submit'][] = array(
      $plugin,
      'settingsFormSubmit',
    );
  }
  $form['#validate'][] = 'editor_form_filter_admin_format_validate';
  $form['#submit'][] = 'editor_form_filter_admin_format_submit';
}