Same filename and directory in other branches
- 8.9.x core/modules/editor/src/Form/EditorLinkDialog.php
- 9 core/modules/editor/src/Form/EditorLinkDialog.php
Namespace
Drupal\editor\Form
File
core/modules/editor/src/Form/EditorLinkDialog.php
View source
<?php
namespace Drupal\editor\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\editor\Entity\Editor;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\HtmlCommand;
use Drupal\editor\Ajax\EditorDialogSave;
use Drupal\Core\Ajax\CloseModalDialogCommand;
class EditorLinkDialog extends FormBase {
public function __construct() {
@trigger_error(__NAMESPACE__ . '\\EditorLinkDialog is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3291493', E_USER_DEPRECATED);
}
public function getFormId() {
return 'editor_link_dialog';
}
public function buildForm(array $form, FormStateInterface $form_state, Editor $editor = NULL) {
$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>';
$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'),
'#submit' => [],
'#ajax' => [
'callback' => '::submitForm',
'event' => 'click',
],
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();
if ($form_state
->getErrors()) {
unset($form['#prefix'], $form['#suffix']);
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
$response
->addCommand(new HtmlCommand('#editor-link-dialog-form', $form));
}
else {
$response
->addCommand(new EditorDialogSave($form_state
->getValues()));
$response
->addCommand(new CloseModalDialogCommand());
}
return $response;
}
}
Classes