public function CourseEntityForm::save in Course 3.x
Same name and namespace in other branches
- 8.3 src/Form/CourseEntityForm.php \Drupal\course\Form\CourseEntityForm::save()
- 8.2 src/Form/CourseEntityForm.php \Drupal\course\Form\CourseEntityForm::save()
Redirect to the outline form after course creation.
Overrides EntityForm::save
File
- src/
Form/ CourseEntityForm.php, line 16
Class
Namespace
Drupal\course\FormCode
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(),
]);
}
}