You are here

public function TrueFalseQuestion::getNodeView in Quiz 8.6

Same name and namespace in other branches
  1. 8.5 question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseQuestion.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseQuestion::getNodeView()
  2. 6.x question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseQuestion.php \Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseQuestion::getNodeView()

Retrieve information relevant for viewing the node.

(This data is generally added to the node's extra field.)

Return value

array Content array.

Overrides QuizQuestionEntityTrait::getNodeView

File

question_types/quiz_truefalse/src/Plugin/quiz/QuizQuestion/TrueFalseQuestion.php, line 23

Class

TrueFalseQuestion
@QuizQuestion ( id = "truefalse", label = Plugin annotation @Translation("True/false question"), handlers = { "response" = "\Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion\TrueFalseResponse" } )

Namespace

Drupal\quiz_truefalse\Plugin\quiz\QuizQuestion

Code

public function getNodeView() {
  $content = parent::getNodeView();
  if ($this
    ->viewCanRevealCorrect()) {
    $answer = $this->node->correct_answer ? t('True') : t('False');
    $content['answers']['#markup'] = '<div class="quiz-solution">' . $answer . '</div>';
    $content['answers']['#weight'] = 2;
  }
  else {
    $content['answers'] = array(
      '#markup' => '<div class="quiz-answer-hidden">' . t('Answer hidden') . '</div>',
      '#weight' => 2,
    );
  }
  return $content;
}