You are here

public function CkeditorAbbreviationDialog::buildForm in CKEditor Abbreviation 2.0.x

Parameters

array $form: The form array.

Drupal\Core\Form\FormStateInterface $form_state: The form's state.

Drupal\editor\Entity\Editor $editor: The editor.

Overrides FormInterface::buildForm

File

src/Form/CkeditorAbbreviationDialog.php, line 36

Class

CkeditorAbbreviationDialog
Provides an abbreviation dialog for text editors.

Namespace

Drupal\ckeditor_abbreviation\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Editor $editor = NULL) {

  // The default values are set directly from \Drupal::request()->request,
  // provided by the editor plugin opening the dialog.
  $user_input = $form_state
    ->getUserInput();
  $input = isset($user_input['editor_object']) ? $user_input['editor_object'] : [];
  $form['#tree'] = TRUE;
  $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
  $form['#prefix'] = '<div id="ckeditor-abbreviation-dialog-form">';
  $form['#suffix'] = '</div>';
  $form['attributes']['text'] = [
    '#title' => $this
      ->t('Abbreviation'),
    '#type' => 'textfield',
    '#default_value' => isset($input['text']) ? $input['text'] : '',
  ];
  $form['attributes']['title'] = [
    '#title' => $this
      ->t('Explanation'),
    '#type' => 'textfield',
    '#default_value' => isset($input['title']) ? $input['title'] : '',
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['save_modal'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitForm',
      'event' => 'click',
    ],
  ];
  return $form;
}