public function EditForm::submitForm in bootstrap simple carousel 8
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
- src/
Form/ EditForm.php, line 198
Class
- EditForm
- Class EditForm.
Namespace
Drupal\bootstrap_simple_carousel\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if (!empty($form_state
->getValue('image_id'))) {
$file = $this->entityTypeManager
->getStorage('file')
->load(current($form_state
->getValue('image_id')));
$file
->setPermanent();
$file
->save();
}
$form_state
->cleanValues();
foreach ($form_state
->getValues() as $field => $value) {
$this->entity
->set($field, $value);
}
try {
$messageStatus = MessengerInterface::TYPE_STATUS;
$this->entity
->save();
$message = $this
->t('Item successfully saved!');
} catch (\Exception $e) {
$message = $this
->t('Record was not saved!') . $e
->getMessage();
$messageStatus = MessengerInterface::TYPE_ERROR;
$this->logger
->error('Can not save carousel item: ' . $e
->getMessage(), [
'exception' => $e,
'data' => $form_state
->getValues(),
]);
}
$this
->messenger()
->addMessage($message, $messageStatus);
$form_state
->setRedirect('bootstrap_simple_carousel.table');
}