public function PetForm::save in Previewable email templates 8.4
Same name and namespace in other branches
- 8 src/Form/PetForm.php \Drupal\pet\Form\PetForm::save()
- 8.3 src/Form/PetForm.php \Drupal\pet\Form\PetForm::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/ PetForm.php, line 57
Class
- PetForm
- PetForm class.
Namespace
Drupal\pet\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\pet\Entity\Pet $pet */
$pet = $this->entity;
$form_state
->setRedirect('entity.pet.collection');
$status = $pet
->save();
$pet_title = [
'%name' => $pet
->label(),
];
$messenger = \Drupal::messenger();
if ($status == SAVED_UPDATED) {
$messenger
->addMessage($this
->t('The email template %name has been updated.', $pet_title));
}
elseif ($status == SAVED_NEW) {
$messenger
->addMessage($this
->t('The email template %name has been added.', $pet_title));
}
}