You are here

public function GroupForm::save in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Form/GroupForm.php \Drupal\group\Entity\Form\GroupForm::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/GroupForm.php, line 81

Class

GroupForm
Form controller for the group add and edit forms.

Namespace

Drupal\group\Entity\Form

Code

public function save(array $form, FormStateInterface $form_state) {

  // We call the parent function first so the entity is saved. We can then
  // read out its ID and redirect to the canonical route.
  $return = parent::save($form, $form_state);

  // Display success message.
  $t_args = [
    '@type' => $this->entity
      ->getGroupType()
      ->label(),
    '%title' => $this->entity
      ->label(),
  ];
  $this
    ->messenger()
    ->addStatus($this->operation == 'edit' ? $this
    ->t('@type %title has been updated.', $t_args) : $this
    ->t('@type %title has been created.', $t_args));
  $form_state
    ->setRedirect('entity.group.canonical', [
    'group' => $this->entity
      ->id(),
  ]);
  return $return;
}