public function EditorImageDialog::submitForm in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/editor/src/Form/EditorImageDialog.php \Drupal\editor\Form\EditorImageDialog::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- core/
modules/ editor/ src/ Form/ EditorImageDialog.php, line 207 - Contains \Drupal\editor\Form\EditorImageDialog.
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(array(
'fid',
0,
));
if (!empty($fid)) {
$file = $this->fileStorage
->load($fid);
$file_url = file_create_url($file
->getFileUri());
// Transform absolute image URLs to relative image URLs: prevent problems
// on multisite set-ups and prevent mixed content errors.
$file_url = file_url_transform_relative($file_url);
$form_state
->setValue(array(
'attributes',
'src',
), $file_url);
$form_state
->setValue(array(
'attributes',
'data-entity-uuid',
), $file
->uuid());
$form_state
->setValue(array(
'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(array(
'attributes',
'alt',
))) === '""') {
$form_state
->setValue(array(
'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;
}