You are here

public function CourseObjectCertificate::take in Course 3.x

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

Code

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