public function CertificateForm::save in Opigno certificate 8
Same name and namespace in other branches
- 3.x 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_certificateCode
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>');
}
}
}