public function ContactFormEditForm::save in Drupal 8
Same name and namespace in other branches
- 9 core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::save()
- 10 core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::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
- core/
modules/ contact/ src/ ContactFormEditForm.php, line 161
Class
- ContactFormEditForm
- Base form for contact form edit forms.
Namespace
Drupal\contactCode
public function save(array $form, FormStateInterface $form_state) {
$contact_form = $this->entity;
$status = $contact_form
->save();
$contact_settings = $this
->config('contact.settings');
$edit_link = $this->entity
->toLink($this
->t('Edit'))
->toString();
$view_link = $contact_form
->toLink($contact_form
->label(), 'canonical')
->toString();
if ($status == SAVED_UPDATED) {
$this
->messenger()
->addStatus($this
->t('Contact form %label has been updated.', [
'%label' => $view_link,
]));
$this
->logger('contact')
->notice('Contact form %label has been updated.', [
'%label' => $contact_form
->label(),
'link' => $edit_link,
]);
}
else {
$this
->messenger()
->addStatus($this
->t('Contact form %label has been added.', [
'%label' => $view_link,
]));
$this
->logger('contact')
->notice('Contact form %label has been added.', [
'%label' => $contact_form
->label(),
'link' => $edit_link,
]);
}
// Update the default form.
if ($form_state
->getValue('selected')) {
$contact_settings
->set('default_form', $contact_form
->id())
->save();
}
elseif ($contact_settings
->get('default_form') == $contact_form
->id()) {
$contact_settings
->set('default_form', NULL)
->save();
}
$form_state
->setRedirectUrl($contact_form
->toUrl('collection'));
}