You are here

public function GroupForm::save in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Form/GroupForm.php \Drupal\rng\Form\GroupForm::save()
  2. 3.x src/Form/GroupForm.php \Drupal\rng\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/Form/GroupForm.php, line 41

Class

GroupForm
Form controller for registration groups.

Namespace

Drupal\rng\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $group = $this->entity
    ->setSource(NULL);
  $event = $group
    ->getEvent();
  $is_new = $group
    ->isNew();
  $group
    ->save();
  $t_args = [
    '%label' => $group
      ->label(),
  ];
  if ($is_new) {
    drupal_set_message(t('Group %label has been created.', $t_args));
  }
  else {
    drupal_set_message(t('Group %label was updated.', $t_args));
  }
  $form_state
    ->setRedirect('rng.event.' . $event
    ->getEntityTypeId() . '.group.list', [
    $event
      ->getEntityTypeId() => $event
      ->id(),
  ]);
}