public function CourseObjectCertificate::take in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_certificate/src/Plugin/course/CourseObject/CourseObjectCertificate.php \Drupal\course_certificate\Plugin\course\CourseObject\CourseObjectCertificate::take()
- 8.2 modules/course_certificate/src/Plugin/course/CourseObject/CourseObjectCertificate.php \Drupal\course_certificate\Plugin\course\CourseObject\CourseObjectCertificate::take()
Course object entry point for taking. This method should return a value corresponding to the type set in getTakeType().
Overrides CourseObject::take
File
- modules/
course_certificate/ src/ Plugin/ course/ CourseObject/ CourseObjectCertificate.php, line 21
Class
- CourseObjectCertificate
- Plugin annotation @CourseObject( id = "certificate", label = "Certificate", handlers = { "fulfillment" = "\Drupal\course\Entity\CourseObjectFulfillment" } )
Namespace
Drupal\course_certificate\Plugin\course\CourseObjectCode
public function take() {
$account = Drupal::currentUser();
$opts = [
'course' => $this
->getCourse()
->id(),
];
// Fulfill immediately.
$this
->getFulfillment($account)
->setComplete(1)
->save();
$render[] = Link::createFromRoute(t('Download certificate'), 'certificate.course', $opts)
->toRenderable();
return $render;
}