CertificateForm.php in Opigno certificate 3.x
File
src/CertificateForm.php
View source
<?php
namespace Drupal\opigno_certificate;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
class CertificateForm extends ContentEntityForm {
public function save(array $form, FormStateInterface $form_state) {
$opigno_certificate = $this->entity;
$insert = $opigno_certificate
->isNew();
$opigno_certificate
->save();
$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>');
}
}
}
}