You are here

public function RegistrationTypeForm::save in RNG - Events and Registrations 3.x

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

Class

RegistrationTypeForm
Form controller for registration types.

Namespace

Drupal\rng\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $registration_type = $this
    ->getEntity();
  $status = $registration_type
    ->save();
  $message = $status == SAVED_UPDATED ? '%label registration type was updated.' : '%label registration type was added.';
  $url = $registration_type
    ->toUrl();
  $t_args = [
    '%label' => $registration_type
      ->label(),
    'link' => Link::fromTextAndUrl(t('Edit'), $url),
  ];
  $this
    ->messenger()
    ->addMessage($this
    ->t($message, $t_args));
  $this
    ->logger('rng')
    ->notice($message, $t_args);
  $form_state
    ->setRedirect('rng.registration_type.overview');
}