You are here

class CourseEventSubscriber in Course 8.3

Same name and namespace in other branches
  1. 8.2 src/EventSubscriber/CourseEventSubscriber.php \Drupal\course\EventSubscriber\CourseEventSubscriber
  2. 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'
course.services.yml in ./course.services.yml
course.services.yml
1 service uses CourseEventSubscriber
course.event_subscriber in ./course.services.yml
\Drupal\course\EventSubscriber\CourseEventSubscriber

File

src/EventSubscriber/CourseEventSubscriber.php, line 12

Namespace

Drupal\course\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
CourseEventSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
CourseEventSubscriber::onRequest public function Check if the current node will fulfill an object.