class CourseContentEventSubscriber in Course 3.x
Same name and namespace in other branches
- 8.3 modules/course_content/src/EventSubscriber/CourseContentEventSubscriber.php \Drupal\course_content\EventSubscriber\CourseContentEventSubscriber
- 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
File
- modules/
course_content/ src/ EventSubscriber/ CourseContentEventSubscriber.php, line 12
Namespace
Drupal\course_content\EventSubscriberView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseContentEventSubscriber:: |
public static | function | Set the priority to 28 so we run in time for the dynamic cache. | |
CourseContentEventSubscriber:: |
public | function | If the current node is a course object, fulfill it for the current user. |