You are here

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

Same name and namespace in other branches
  1. 8.3 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::context()
  2. 8.2 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::context()

Course context handler callback.

Overrides CourseObject::context

File

modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php, line 30

Class

CourseObjectQuiz
Plugin annotation @CourseObject( id = "quiz", label = "Quiz", handlers = { "fulfillment" = "\Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuizFulfillment" } )

Namespace

Drupal\course_quiz\Plugin\course\CourseObject

Code

public static function context() {
  $route_match = Drupal::routeMatch();
  if (in_array($route_match
    ->getRouteName(), [
    'entity.quiz.canonical',
    'quiz.take',
    'quiz.question.feedback',
    'quiz.question.take',
    'entity.quiz_result.canonical',
  ])) {
    $quiz = $route_match
      ->getParameter('quiz');
    if (is_numeric($quiz)) {
      $quiz = Quiz::load($quiz);
    }
    if ($courseObject = course_get_course_object('quiz', $quiz
      ->id())) {
      return array(
        'object_type' => 'quiz',
        'instance' => $quiz
          ->id(),
      );
    }
  }
}