You are here

public function CodeMirror::settingsForm in CKEditor CodeMirror 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/CKEditorPlugin/CodeMirror.php \Drupal\ckeditor_codemirror\Plugin\CKEditorPlugin\CodeMirror::settingsForm()

Returns a settings form to configure this CKEditor plugin.

If the plugin's behavior depends on extensive options and/or external data, then the implementing module can choose to provide a separate, global configuration page rather than per-text-editor settings. In that case, this form should provide a link to the separate settings page.

Parameters

array $form: An empty form array to be populated with a configuration form, if any.

\Drupal\Core\Form\FormStateInterface $form_state: The state of the entire filter administration form.

\Drupal\editor\Entity\Editor $editor: A configured text editor object.

Return value

array A render array for the settings form.

Overrides CKEditorPluginConfigurableInterface::settingsForm

File

src/Plugin/CKEditorPlugin/CodeMirror.php, line 119

Class

CodeMirror
Defines the "CodeMirror" plugin.

Namespace

Drupal\ckeditor_codemirror\Plugin\CKEditorPlugin

Code

public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
  $editor_settings = $editor
    ->getSettings();
  if (isset($editor_settings['plugins']['codemirror'])) {
    $settings = $editor_settings['plugins']['codemirror'];
  }
  $form['#attached']['library'][] = 'ckeditor_codemirror/ckeditor_codemirror.admin';
  $form['enable'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable CodeMirror source view syntax highlighting.'),
    '#default_value' => isset($settings['enable']) ? $settings['enable'] : FALSE,
  ];
  $form['startupMode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Editor startup Mode'),
    '#options' => [
      'wysiwyg' => $this
        ->t('WYSIWYG (default)'),
      'source' => $this
        ->t('Source'),
    ],
    '#default_value' => isset($settings['startupMode']) ? $settings['startupMode'] : 'wysiwyg',
  ];
  $form['mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Mode'),
    '#options' => [
      'htmlmixed' => $this
        ->t('HTML (including css, xml and javascript)'),
      'text/html' => $this
        ->t('HTML only'),
      'application/x-httpd-php' => $this
        ->t('PHP (including HTML)'),
      'text/javascript' => $this
        ->t('Javascript only'),
    ],
    '#default_value' => isset($settings['mode']) ? $settings['mode'] : 'htmlmixed',
  ];
  $theme_options = [
    'default' => 'default',
  ];
  $themes_directory = _ckeditor_codemirror_get_library_path() . '/codemirror/theme';
  if (is_dir($themes_directory)) {
    $theme_css_files = file_scan_directory($themes_directory, '/\\.css/i');
    foreach ($theme_css_files as $file) {
      $theme_options[$file->name] = $file->name;
    }
  }
  $form['theme'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Theme'),
    '#options' => $theme_options,
    '#default_value' => isset($settings['theme']) ? $settings['theme'] : 'default',
  ];
  $form['options'] = [
    '#type' => 'details',
    '#title' => t('Additional settings'),
    '#description' => t('Source highlighting and code formatting options:'),
    '#open' => FALSE,
  ];
  foreach ($this
    ->options() as $setting => $description) {
    $form['options'][$setting] = [
      '#type' => 'checkbox',
      '#title' => $description,
      '#default_value' => isset($settings['options'][$setting]) ? $settings['options'][$setting] : TRUE,
    ];
  }
  return $form;
}