public function ContentModerationNotificationsFormBase::save in Content Moderation Notifications 8
Same name and namespace in other branches
- 8.3 src/Form/ContentModerationNotificationsFormBase.php \Drupal\content_moderation_notifications\Form\ContentModerationNotificationsFormBase::save()
- 8.2 src/Form/ContentModerationNotificationsFormBase.php \Drupal\content_moderation_notifications\Form\ContentModerationNotificationsFormBase::save()
Overrides Drupal\Core\Entity\EntityFormController::save().
Saves the entity. This is called after submit() has built the entity from the form values. Do not override submit() as save() is the preferred method for entity form controllers.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.
Overrides EntityForm::save
File
- src/
Form/ ContentModerationNotificationsFormBase.php, line 272
Class
- ContentModerationNotificationsFormBase
- Class ContentModerationNotificationFormBase.
Namespace
Drupal\content_moderation_notifications\FormCode
public function save(array $form, FormStateInterface $form_state) {
// EntityForm provides us with the entity we're working on.
$content_moderation_notification = $this
->getEntity();
// Drupal already populated the form values in the entity object. Each
// form field was saved as a public variable in the entity class. PHP
// allows Drupal to do this even if the method is not defined ahead of
// time.
$status = $content_moderation_notification
->save();
// Grab the URL of the new entity. We'll use it in the message.
$url = $content_moderation_notification
->urlInfo();
// Create an edit link.
$edit_link = Link::fromTextAndUrl($this
->t('Edit'), $url)
->toString();
if ($status == SAVED_UPDATED) {
// If we edited an existing entity...
drupal_set_message($this
->t('Notification has been updated.', array(
'%label' => $content_moderation_notification
->label(),
)));
$this
->logger('contact')
->notice('Notification has been updated.', [
'%label' => $content_moderation_notification
->label(),
'link' => $edit_link,
]);
}
else {
// If we created a new entity...
drupal_set_message($this
->t('Notification has been added.', array(
'%label' => $content_moderation_notification
->label(),
)));
$this
->logger('contact')
->notice('Notification has been added.', [
'%label' => $content_moderation_notification
->label(),
'link' => $edit_link,
]);
}
// Redirect the user back to the listing route after the save operation.
$form_state
->setRedirect('entity.content_moderation_notification.list');
}