function EditorImageDialog::submitForm
Same name in other branches
- 9 core/modules/editor/src/Form/EditorImageDialog.php \Drupal\editor\Form\EditorImageDialog::submitForm()
- 10 core/modules/editor/src/Form/EditorImageDialog.php \Drupal\editor\Form\EditorImageDialog::submitForm()
Overrides FormInterface::submitForm
File
-
core/
modules/ editor/ src/ Form/ EditorImageDialog.php, line 202
Class
- EditorImageDialog
- Provides an image dialog for text editors.
Namespace
Drupal\editor\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$response = new AjaxResponse();
// Convert any uploaded files from the FID values to data-entity-uuid
// attributes and set data-entity-type to 'file'.
$fid = $form_state->getValue([
'fid',
0,
]);
if (!empty($fid)) {
/** @var \Drupal\file\FileInterface $file */
$file = $this->fileStorage
->load($fid);
$file_url = $file->createFileUrl();
$form_state->setValue([
'attributes',
'src',
], $file_url);
$form_state->setValue([
'attributes',
'data-entity-uuid',
], $file->uuid());
$form_state->setValue([
'attributes',
'data-entity-type',
], 'file');
}
// When the alt attribute is set to two double quotes, transform it to the
// empty string: two double quotes signify "empty alt attribute". See above.
if (trim($form_state->getValue([
'attributes',
'alt',
])) === '""') {
$form_state->setValue([
'attributes',
'alt',
], '');
}
if ($form_state->getErrors()) {
unset($form['#prefix'], $form['#suffix']);
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
$response->addCommand(new HtmlCommand('#editor-image-dialog-form', $form));
}
else {
$response->addCommand(new EditorDialogSave($form_state->getValues()));
$response->addCommand(new CloseModalDialogCommand());
}
return $response;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.