You are here

public static function CourseObjectPoll::context in Course 3.x

Course context handler callback.

Overrides CourseObject::context

File

modules/course_poll/src/Plugin/course/CourseObject/CourseObjectPoll.php, line 27

Class

CourseObjectPoll
Plugin annotation @CourseObject( id = "poll", label = "Poll", handlers = { "fulfillment" = "\Drupal\course_poll\Plugin\course\CourseObject\CourseObjectPollFulfillment" } )

Namespace

Drupal\course_poll\Plugin\course\CourseObject

Code

public static function context() {
  $route_match = Drupal::routeMatch();
  if (in_array($route_match
    ->getRouteName(), [
    'entity.poll.canonical',
  ])) {
    $poll = $route_match
      ->getParameter('poll');
    if ($courseObject = course_get_course_object('poll', $poll
      ->id())) {
      return array(
        'object_type' => 'poll',
        'instance' => $poll
          ->id(),
      );
    }
  }
}