You are here

public function EditorLinkDialog::buildForm in Zircon Profile 8

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

Parameters

\Drupal\filter\Entity\FilterFormat $filter_format: The filter format for which this dialog corresponds.

Overrides FormInterface::buildForm

File

core/modules/editor/src/Form/EditorLinkDialog.php, line 36
Contains \Drupal\editor\Form\EditorLinkDialog.

Class

EditorLinkDialog
Provides a link dialog for text editors.

Namespace

Drupal\editor\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = 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'] : array();
  $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'] = array(
    '#title' => $this
      ->t('URL'),
    '#type' => 'textfield',
    '#default_value' => isset($input['href']) ? $input['href'] : '',
    '#maxlength' => 2048,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['save_modal'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => array(),
    '#ajax' => array(
      'callback' => '::submitForm',
      'event' => 'click',
    ),
  );
  return $form;
}