public function RngContactForm::save in RNG Contact 8
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/ RngContactForm.php, line 37
Class
- RngContactForm
- Form controller for contacts.
Namespace
Drupal\rng_contact\FormCode
public function save(array $form, FormStateInterface $form_state) {
$contact = $this->entity;
$is_new = $contact
->isNew();
$contact
->save();
$t_args = [
'%label' => $contact
->label(),
];
if ($is_new) {
drupal_set_message(t('Contact %label has been created.', $t_args));
}
else {
drupal_set_message(t('Contact %label was updated.', $t_args));
}
if (!$contact
->isNew() && $contact
->access('view')) {
$form_state
->setRedirect('entity.rng_contact.canonical', [
'rng_contact' => $contact
->id(),
]);
}
else {
$form_state
->setRedirect('<front>');
}
}