You are here

public function TeamRoleForm::save in Apigee Edge 8

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

modules/apigee_edge_teams/src/Form/TeamRoleForm.php, line 44

Class

TeamRoleForm
Class TeamRoleForm.

Namespace

Drupal\apigee_edge_teams\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $team_role = $this->entity;
  $status = $team_role
    ->save();
  $context = [
    '%label' => $team_role
      ->label(),
    '@entity-type' => mb_strtolower($team_role
      ->getEntityType()
      ->getSingularLabel()),
  ];
  if ($status == SAVED_NEW) {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Created the %label @entity-type.', $context));
  }
  else {
    $this
      ->messenger()
      ->addStatus($this
      ->t('Saved the %label @entity-type.', $context));
  }
  $form_state
    ->setRedirectUrl($team_role
    ->toUrl('collection'));
}