public function ModalForm::save in Modal 5.0.x
Same name and namespace in other branches
- 8.3 src/Form/ModalForm.php \Drupal\modal_page\Form\ModalForm::save()
- 8.2 src/Form/ModalForm.php \Drupal\modal_page\Form\ModalForm::save()
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
File
- src/
Form/ ModalForm.php, line 375
Class
- ModalForm
- Class ModalForm.
Namespace
Drupal\modal_page\FormCode
public function save(array $form, FormStateInterface $form_state) {
$modal = $this->entity;
$body = '';
if (!empty($form_state
->getValue('body'))) {
$body = $form_state
->getValue('body');
}
$modal
->setBody($body);
$pages = '';
if (!empty($form_state
->getValue('pages'))) {
$pages = $form_state
->getValue('pages');
}
$modal
->setPages($pages);
$status = $modal
->save();
switch ($status) {
case SAVED_NEW:
$this
->messenger()
->addMessage($this
->t('Created the %label Modal.', [
'%label' => $modal
->label(),
]));
break;
default:
$this
->messenger()
->addMessage($this
->t('Saved the %label Modal.', [
'%label' => $modal
->label(),
]));
}
$form_state
->setRedirectUrl($modal
->toUrl('collection'));
// Clear Views' cache.
drupal_flush_all_caches();
}