function EditorLinkDialog::buildForm

Same name in other branches
  1. 9 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

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

Overrides FormInterface::buildForm

File

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

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;
}

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