You are here

public function CourseObjectQuiz::getWarnings in Course 8.3

Same name and namespace in other branches
  1. 8.2 modules/course_quiz/src/Plugin/course/CourseObject/CourseObjectQuiz.php \Drupal\course_quiz\Plugin\course\CourseObject\CourseObjectQuiz::getWarnings()
  2. 3.x 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 114

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 = Drupal\quiz\Entity\Quiz::load($this
      ->getInstanceId());
    if (!$quiz
      ->getNumberOfQuestions()) {
      $link = Drupal\Core\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;
}