CourseEntityForm.php in Course 3.x
File
src/Form/CourseEntityForm.php
View source
<?php
namespace Drupal\course\Form;
use Drupal\course\Entity\CourseType;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
class CourseEntityForm extends ContentEntityForm {
public function save(array $form, FormStateInterface $form_state) {
$course = $this->entity;
$insert = $course
->isNew();
parent::save($form, $form_state);
$type = CourseType::load($course
->bundle());
$node_link = $course
->toLink($this
->t('View'))
->toString();
$context = [
'@type' => $course
->bundle(),
'%title' => $course
->label(),
'link' => $node_link,
];
$t_args = [
'@type' => $type
->label(),
'%title' => $course
->toLink()
->toString(),
];
if ($insert) {
$this
->logger('course')
->notice('@type: added %title.', $context);
$this
->messenger()
->addStatus($this
->t('@type %title has been created.', $t_args));
$form_state
->setRedirect('entity.course.canonical', [
'course' => $this->entity
->id(),
]);
}
else {
$this
->logger('course')
->notice('@type: updated %title.', $context);
$this
->messenger()
->addStatus($this
->t('@type %title has been updated.', $t_args));
$form_state
->setRedirect('entity.course.canonical', [
'course' => $this->entity
->id(),
]);
}
}
}