function WorkspaceForm::save
Same name in other branches
- 9 core/modules/workspaces/src/Form/WorkspaceForm.php \Drupal\workspaces\Form\WorkspaceForm::save()
- 8.9.x core/modules/workspaces/src/Form/WorkspaceForm.php \Drupal\workspaces\Form\WorkspaceForm::save()
- 10 core/modules/workspaces/src/Form/WorkspaceForm.php \Drupal\workspaces\Form\WorkspaceForm::save()
Overrides EntityForm::save
File
-
core/
modules/ workspaces/ src/ Form/ WorkspaceForm.php, line 122
Class
- WorkspaceForm
- Form controller for the workspace edit forms.
Namespace
Drupal\workspaces\FormCode
public function save(array $form, FormStateInterface $form_state) {
$workspace = $this->entity;
$workspace->setNewRevision(TRUE);
$status = $workspace->save();
$info = [
'%info' => $workspace->label(),
];
$context = [
'@type' => $workspace->bundle(),
'%info' => $workspace->label(),
];
$logger = $this->logger('workspaces');
if ($status == SAVED_UPDATED) {
$logger->notice('@type: updated %info.', $context);
$this->messenger()
->addMessage($this->t('Workspace %info has been updated.', $info));
}
else {
$logger->notice('@type: added %info.', $context);
$this->messenger()
->addMessage($this->t('Workspace %info has been created.', $info));
}
if ($workspace->id()) {
$form_state->setValue('id', $workspace->id());
$form_state->set('id', $workspace->id());
$collection_url = $workspace->toUrl('collection');
$redirect = $collection_url->access() ? $collection_url : Url::fromRoute('<front>');
$form_state->setRedirectUrl($redirect);
}
else {
$this->messenger()
->addError($this->t('The workspace could not be saved.'));
$form_state->setRebuild();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.