public function MailingListForm::save in Mailing List 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/ MailingListForm.php, line 221
Class
- MailingListForm
- Form handler for mailing list forms.
Namespace
Drupal\mailing_list\FormCode
public function save(array $form, FormStateInterface $form_state) {
/** @var \Drupal\mailing_list\Entity\MailingList $mailing_list */
$mailing_list = $this->entity;
$status = $mailing_list
->save();
$t_args = [
'%name' => $mailing_list
->label(),
];
if ($status == SAVED_UPDATED) {
drupal_set_message(t('The mailing list %name has been updated.', $t_args));
}
elseif ($status == SAVED_NEW) {
drupal_set_message(t('The mailing list %name has been added.', $t_args));
$context = array_merge($t_args, [
'link' => $mailing_list
->toLink($this
->t('View'), 'collection')
->toString(),
]);
$this
->logger('mailing_list')
->notice('Added mailing list %name.', $context);
}
$this->entityManager
->clearCachedFieldDefinitions();
$form_state
->setRedirectUrl($mailing_list
->toUrl('collection'));
}