You are here

public function CertificateForm::save in Opigno certificate 3.x

Same name and namespace in other branches
  1. 8 src/CertificateForm.php \Drupal\opigno_certificate\CertificateForm::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/CertificateForm.php, line 16

Class

CertificateForm
Form handler for the opigno_certificate form.

Namespace

Drupal\opigno_certificate

Code

public function save(array $form, FormStateInterface $form_state) {
  $opigno_certificate = $this->entity;
  $insert = $opigno_certificate
    ->isNew();
  $opigno_certificate
    ->save();

  /*$opigno_certificate_link = $opigno_certificate->link($this->t('View'));*/
  $t_args = [
    '%label' => $opigno_certificate
      ->tolink($opigno_certificate
      ->label())
      ->toString(),
  ];
  if ($insert) {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Certificate %label has been created.', $t_args));
  }
  else {
    \Drupal::messenger()
      ->addMessage($this
      ->t('Certificate %label has been updated.', $t_args));
  }
  if ($opigno_certificate
    ->id()) {
    if ($opigno_certificate
      ->access('view')) {
      $form_state
        ->setRedirect('entity.opigno_certificate.canonical', [
        'opigno_certificate' => $opigno_certificate
          ->id(),
      ]);
    }
    else {
      $form_state
        ->setRedirect('<front>');
    }
  }
}