public function CourseObjectCertificate::take in Course 8.2
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()
- 3.x 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 20
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(),
'account' => $account
->id(),
];
// Fulfill immediately.
$this
->getFulfillment($account)
->setComplete(1)
->save();
$render[] = Link::createFromRoute(t('Download certificate'), 'certificate.course.user', $opts)
->toRenderable();
return $render;
}