You are here

public function CodeMirrorEditorTestForm::buildForm in The CodeMirror Editor 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

tests/codemirror_editor_test/src/Form/CodeMirrorEditorTestForm.php, line 23

Class

CodeMirrorEditorTestForm
Provides a Codemirror test form.

Namespace

Drupal\codemirror_editor_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['editor_1'] = [
    '#type' => 'codemirror',
    '#title' => $this
      ->t('Editor 1'),
    '#rows' => 15,
  ];
  $form['editor_2'] = [
    '#type' => 'codemirror',
    '#title' => $this
      ->t('Editor 2'),
    '#codemirror' => [
      'modeSelect' => [
        'text/html' => $this
          ->t('HTML'),
        'javascript' => $this
          ->t('JavaScript'),
        'css' => $this
          ->t('CSS'),
      ],
      'lineWrapping' => TRUE,
      'lineNumbers' => TRUE,
      'autoCloseTags' => FALSE,
      'styleActiveLine' => TRUE,
      'buttons' => [
        'bold',
        'italic',
        'underline',
      ],
    ],
  ];
  $form['editor_3'] = [
    '#type' => 'codemirror',
    '#title' => $this
      ->t('Editor 3'),
    '#default_value' => "<div>\n  Test\n</div>",
    '#codemirror' => [
      'toolbar' => FALSE,
      'readOnly' => TRUE,
      'height' => 100,
      'foldGutter' => TRUE,
      'mode' => 'text/html',
    ],
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  return $form;
}