CourseContentEventSubscriber.php in Course 3.x
Same filename and directory in other branches
Namespace
Drupal\course_content\EventSubscriberFile
modules/course_content/src/EventSubscriber/CourseContentEventSubscriber.phpView source
<?php
namespace Drupal\course_content\EventSubscriber;
use Drupal;
use Drupal\node\Entity\NodeType;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use function course_get_course_object;
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();
}
}
}
}
}
Classes
Name | Description |
---|---|
CourseContentEventSubscriber |