function EditorLinkDialog::buildForm

Same name in other branches
  1. 8.9.x core/modules/editor/src/Form/EditorLinkDialog.php \Drupal\editor\Form\EditorLinkDialog::buildForm()
  2. 10 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 = $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' => $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.