class CourseEventSubscriber in Course 8.3
Same name and namespace in other branches
- 8.2 src/EventSubscriber/CourseEventSubscriber.php \Drupal\course\EventSubscriber\CourseEventSubscriber
- 3.x src/EventSubscriber/CourseEventSubscriber.php \Drupal\course\EventSubscriber\CourseEventSubscriber
Hierarchy
- class \Drupal\course\EventSubscriber\CourseEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of CourseEventSubscriber
1 string reference to 'CourseEventSubscriber'
1 service uses CourseEventSubscriber
File
- src/
EventSubscriber/ CourseEventSubscriber.php, line 12
Namespace
Drupal\course\EventSubscriberView source
class CourseEventSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
// Set priority to 28 so we can get around the page cache.
KernelEvents::REQUEST => [
'onRequest',
28,
],
];
}
/**
* Check if the current node will fulfill an object.
*
* @param GetResponseEvent $event
*/
public function onRequest(GetResponseEvent $event) {
course_context();
if (!($course = course_get_context())) {
// Set course context for all modules that define course context handlers.
$handlers = course_get_handlers('object');
if (is_array($handlers)) {
foreach ($handlers as $handler) {
// We expect query parameters suitable for course_determine_context().
if ($params = call_user_func(array(
$handler['class'],
'context',
))) {
if (is_array($params) && isset($params['object_type']) && isset($params['instance'])) {
if ($course = course_determine_context($params['object_type'], $params['instance'])) {
// Set the course context.
course_set_context($course);
// Find and set the active object.
$course_object = course_get_course_object($params['object_type'], $params['instance'], $course);
$_SESSION['course'][$course
->id()]['taking']['active'] = $course_object
->id();
}
}
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CourseEventSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
CourseEventSubscriber:: |
public | function | Check if the current node will fulfill an object. |