public function CourseEnrollment::preSave in Course 3.x
Same name and namespace in other branches
- 8.3 src/Entity/CourseEnrollment.php \Drupal\course\Entity\CourseEnrollment::preSave()
- 8.2 src/Entity/CourseEnrollment.php \Drupal\course\Entity\CourseEnrollment::preSave()
If a duration is set on the course, apply it to this enrollment.
Overrides ContentEntityBase::preSave
File
- src/
Entity/ CourseEnrollment.php, line 112
Class
- CourseEnrollment
- Defines the profile entity class.
Namespace
Drupal\course\EntityCode
public function preSave(EntityStorageInterface $storage) {
$course = $this
->getCourse();
if ($this
->get('enroll_end')
->isEmpty() && !$course
->get('duration')
->isEmpty()) {
// Set enrollment end to now + the duration of the course.
$this
->set('enroll_end', \Drupal::time()
->getRequestTime() + $course
->get('duration')
->getString());
}
// After enrollment, check for completion.
$this
->evaluate();
// Always create a new revision.
$this
->setNewRevision();
parent::preSave($storage);
}