You are here

public function EditorLinkDialog::buildForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/editor/src/Form/EditorLinkDialog.php \Drupal\editor\Form\EditorLinkDialog::buildForm()

Parameters

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

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

\Drupal\editor\Entity\Editor $editor: The text editor to which this dialog corresponds.

Return value

array

Overrides FormInterface::buildForm

File

core/modules/editor/src/Form/EditorLinkDialog.php, line 39

Class

EditorLinkDialog
Provides a link dialog for text editors.

Namespace

Drupal\editor\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="editor-link-dialog-form">';
  $form['#suffix'] = '</div>';

  // Everything under the "attributes" key is merged directly into the
  // generated link tag's attributes.
  $form['attributes']['href'] = [
    '#title' => $this
      ->t('URL'),
    '#type' => 'textfield',
    '#default_value' => isset($input['href']) ? $input['href'] : '',
    '#maxlength' => 2048,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['save_modal'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitForm',
      'event' => 'click',
    ],
  ];
  return $form;
}