You are here

public function CourseObjectQuiz::getWarnings 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::getWarnings()
  2. 8.2 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::getWarnings()

Let the user know if they have a Quiz without questions.

Overrides CourseHandler::getWarnings

File

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

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 function getWarnings() {
  $warnings = parent::getWarnings();
  if ($this
    ->getInstanceId()) {
    $quiz = Quiz::load($this
      ->getInstanceId());
    if (!$quiz
      ->getNumberOfQuestions()) {
      $link = Link::createFromRoute('add questions', "quiz.questions", [
        'quiz' => $this
          ->getInstanceId(),
      ]);
      $warnings[] = t('This Quiz does not have any questions. Please @link.', array(
        '@link' => $link
          ->toString(),
      ));
    }
  }
  return $warnings;
}