You are here

class CourseContentEventSubscriber in Course 3.x

Same name and namespace in other branches
  1. 8.3 modules/course_content/src/EventSubscriber/CourseContentEventSubscriber.php \Drupal\course_content\EventSubscriber\CourseContentEventSubscriber
  2. 8.2 modules/course_content/src/EventSubscriber/CourseContentEventSubscriber.php \Drupal\course_content\EventSubscriber\CourseContentEventSubscriber

Hierarchy

  • class \Drupal\course_content\EventSubscriber\CourseContentEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of CourseContentEventSubscriber

1 string reference to 'CourseContentEventSubscriber'
course_content.services.yml in modules/course_content/course_content.services.yml
modules/course_content/course_content.services.yml
1 service uses CourseContentEventSubscriber
course_content_event_subscriber in modules/course_content/course_content.services.yml
\Drupal\course_content\EventSubscriber\CourseContentEventSubscriber

File

modules/course_content/src/EventSubscriber/CourseContentEventSubscriber.php, line 12

Namespace

Drupal\course_content\EventSubscriber
View source
class CourseContentEventSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   *
   * Set the priority to 28 so we run in time for the dynamic cache.
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::REQUEST => [
        'onRequest',
        28,
      ],
    ];
  }

  /**
   * If the current node is a course object, fulfill it for the current user.
   *
   * @param GetResponseEvent $event
   */
  public function onRequest(GetResponseEvent $event) {
    $route_match = Drupal::routeMatch();
    if ($route_match
      ->getRouteName() == 'entity.node.canonical') {
      $node = $route_match
        ->getParameter('node');
      $type = NodeType::load($node
        ->bundle());
      if ($type
        ->getThirdPartySetting('course_content', 'use')) {
        $account = Drupal::currentUser();
        if ($courseObject = course_get_course_object('content', $node
          ->id())) {
          $courseObject
            ->getFulfillment($account)
            ->setComplete()
            ->save();
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CourseContentEventSubscriber::getSubscribedEvents public static function Set the priority to 28 so we run in time for the dynamic cache.
CourseContentEventSubscriber::onRequest public function If the current node is a course object, fulfill it for the current user.