You are here

public function CourseObjectCertificate::take in Course 8.3

Same name and namespace in other branches
  1. 8.2 modules/course_certificate/src/Plugin/course/CourseObject/CourseObjectCertificate.php \Drupal\course_certificate\Plugin\course\CourseObject\CourseObjectCertificate::take()
  2. 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\CourseObject

Code

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;
}