public function MediaGalleryForm::save in Media Gallery 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/ MediaGalleryForm.php, line 16
Class
- MediaGalleryForm
- Form controller for the media gallery entity edit forms.
Namespace
Drupal\media_gallery\FormCode
public function save(array $form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
$result = $entity
->save();
$link = $entity
->toLink($this
->t('View'))
->toRenderable();
$message_arguments = [
'%label' => $this->entity
->label(),
];
$logger_arguments = $message_arguments + [
'link' => render($link),
];
if ($result == SAVED_NEW) {
$this
->messenger()
->addStatus($this
->t('New media gallery %label has been created.', $message_arguments));
$this
->logger('media_gallery')
->notice('Created new media gallery %label', $logger_arguments);
}
else {
$this
->messenger()
->addStatus($this
->t('The media gallery %label has been updated.', $message_arguments));
$this
->logger('media_gallery')
->notice('Updated new media gallery %label.', $logger_arguments);
}
$form_state
->setRedirect('entity.media_gallery.canonical', [
'media_gallery' => $entity
->id(),
]);
}