public function GroupContentForm::save in Group 2.0.x
Same name and namespace in other branches
- 8 src/Entity/Form/GroupContentForm.php \Drupal\group\Entity\Form\GroupContentForm::save()
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/
Entity/ Form/ GroupContentForm.php, line 107
Class
- GroupContentForm
- Form controller for the group content edit forms.
Namespace
Drupal\group\Entity\FormCode
public function save(array $form, FormStateInterface $form_state) {
$return = parent::save($form, $form_state);
/** @var \Drupal\group\Entity\GroupContentInterface $group_content */
$group_content = $this
->getEntity();
// The below redirect ensures the user will be redirected to something they
// can view in the following order: The relationship entity (group content),
// they target entity itself, the group and finally the front page. This
// only applies if there was no destination GET parameter set in the URL.
if ($group_content
->access('view')) {
$form_state
->setRedirectUrl($group_content
->toUrl());
}
elseif ($group_content
->getEntity()
->access('view')) {
$form_state
->setRedirectUrl($group_content
->getEntity()
->toUrl());
}
elseif ($group_content
->getGroup()
->access('view')) {
$form_state
->setRedirectUrl($group_content
->getGroup()
->toUrl());
}
else {
$form_state
->setRedirect('<front>');
}
return $return;
}