function ContactFormEditForm::save
Same name in other branches
- 9 core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::save()
- 8.9.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::save()
- 11.x core/modules/contact/src/ContactFormEditForm.php \Drupal\contact\ContactFormEditForm::save()
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'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.