1 ckeditor5.admin.inc ckeditor5_settings_form(&$form, $form_state, $format)

Editor settings callback; Provide options for CKEditor 5 module.

File

core/modules/ckeditor5/ckeditor5.admin.inc, line 10
Admin page callbacks for the CKEditor 5 module.

Code

function ckeditor5_settings_form(&$form, $form_state, $format) {
  $plugins = ckeditor5_plugins();
  $toolbar_element = theme('ckeditor5_settings_toolbar', array(
    'format' => $format,
    'plugins' => $plugins,
  ));
  $elements = array(
    '#attached' => array(
      'library' => array(
        array('ckeditor5', 'backdrop.ckeditor5.admin'),
      ),
      'js' => array(
        array(
          'data' => array(
            'ckeditor5' => array(
              'toolbarAdmin' => $toolbar_element,
            ),
          ),
          'type' => 'setting',
        ),
      ),
    ),
    '#attributes' => array('class' => array('ckeditor5-toolbar-configuration')),
  );
  $elements['toolbar'] = array(
    '#type' => 'textarea',
    '#title' => t('Toolbar configuration'),
    '#default_value' => json_encode($format->editor_settings['toolbar']),
    '#attributes' => array('class' => array('ckeditor5-toolbar-textarea')),
  );

  $elements['plugins'] = array(
    '#type' => 'vertical_tabs',
  );

  // @todo: Have this settings form be provided via a plugin hook.
  $elements['plugins']['image'] = filter_editor_image_upload_settings_form($format);
  $elements['plugins']['image'] += array(
    '#type' => 'fieldset',
    '#title' => t('Image uploading'),
    '#attributes' => array(
      'class' => array('ckeditor5-plugin-backdropimage'),
      'data-ckeditor5-feature-dependency' => 'backdropImage',
    ),
    '#parents' => array('editor_settings', 'image_upload'),
  );

  $elements['plugins']['file'] = filter_editor_file_upload_settings_form($format);
  $elements['plugins']['file'] += array(
    '#type' => 'fieldset',
    '#title' => t('File uploading'),
    '#attributes' => array(
      'class' => array('ckeditor5-plugin-link'),
      'data-ckeditor5-feature-dependency' => 'backdropLink',
    ),
    '#parents' => array('editor_settings', 'file_upload'),
  );

  $elements['plugins']['style'] = array(
    '#type' => 'fieldset',
    '#title' => t('Style list'),
    '#attributes' => array(
      'class' => array('ckeditor5-plugin-style'),
      'data-ckeditor5-feature-dependency' => 'style',
    ),
  );
  $style_list = '';
  if (isset($format->editor_settings['style_list'])) {
    $style_list = _ckeditor5_settings_stringify_style_list($format->editor_settings['style_list']);
  }
  $elements['plugins']['style']['style_list'] = array(
    '#type' => 'textarea',
    '#rows' => 4,
    '#default_value' => $style_list,
    '#description' => t('A list of classes that will be provided in the "Styles" dropdown. Enter one class on each line in the format: element.class|Label. Example: h1.title|Title.') . '<br />' . t('Each style should be in your theme\'s main CSS as well as in your theme\'s ckeditor5-styles.css file.'),
    '#parents' => array('editor_settings', 'style_list'),
  );

  $elements['plugins']['heading'] = array(
    '#type' => 'fieldset',
    '#title' => t('Headings'),
    '#attributes' => array(
      'class' => array('ckeditor5-plugin-heading'),
      'data-ckeditor5-feature-dependency' => 'heading',
    ),
  );
  $elements['plugins']['heading']['heading_list'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Enabled headings'),
    '#default_value' => $format->editor_settings['heading_list'],
    '#options' => array(
      'h1' => t('Heading 1'),
      'h2' => t('Heading 2'),
      'h3' => t('Heading 3'),
      'h4' => t('Heading 4'),
      'h5' => t('Heading 5'),
      'h6' => t('Heading 6'),
    ),
    '#description' => t('Select heading tags that are shown in the Headings toolbar button. Usually Heading 1 is reserved for the page title and is not shown in the editor.'),
    '#attributes' => array('class' => array('ckeditor5-heading-list')),
    '#parents' => array('editor_settings', 'heading_list'),
  );

  array_unshift($form['#validate'], 'ckeditor5_settings_form_validate');
  array_unshift($form['#submit'], 'ckeditor5_settings_form_submit');
  return $elements;
}