You are here

public function ILTResultForm::save in Opigno Instructor-led Trainings 3.x

Same name and namespace in other branches
  1. 8 src/Form/ILTResultForm.php \Drupal\opigno_ilt\Form\ILTResultForm::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/ILTResultForm.php, line 69

Class

ILTResultForm
Provides a form for creating/editing a opigno_ilt_result entity.

Namespace

Drupal\opigno_ilt\Form

Code

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

  /** @var \Drupal\opigno_ilt\ILTResultInterface $entity */
  $entity = $this->entity;
  $status = parent::save($form, $form_state);

  // Set status message.
  $link = $entity
    ->toLink()
    ->toString();
  if ($status == SAVED_UPDATED) {
    $message = $this
      ->t('The Instructor-Led Training Result %result has been updated.', [
      '%result' => $link,
    ]);
  }
  else {
    $message = $this
      ->t('The Instructor-Led Training Result Workspace %result has been created.', [
      '%result' => $link,
    ]);
  }
  $this
    ->messenger()
    ->addMessage($message);

  // Set redirect.
  $form_state
    ->setRedirect('entity.opigno_ilt_result.canonical', [
    'opigno_ilt_result' => $entity
      ->id(),
  ]);
  return $status;
}