public function ClozeQuestion::getNodeView in Quiz 8.4
Implementation of getNodeView()
Overrides QuizQuestion::getNodeView
See also
QuizQuestion#getNodeView()
File
- question_types/
cloze/ lib/ Drupal/ cloze/ ClozeQuestion.php, line 114 - The main classes for the multichoice question type.
Class
- ClozeQuestion
- Extension of QuizQuestion.
Namespace
Drupal\clozeCode
public function getNodeView() {
$content = parent::getNodeView();
$content['#attached']['css'] = array(
drupal_get_path('module', 'cloze') . '/css/cloze.css',
);
$body = $this->node->body
->getValue();
$question = $body[0]['value'];
$chunks = _cloze_get_question_chunks($question);
if ($this
->viewCanRevealCorrect() && !empty($chunks)) {
$solution = $body[0]['value'];
foreach ($chunks as $position => $chunk) {
if (strpos($chunk, '[') === FALSE) {
continue;
}
$chunk = str_replace(array(
'[',
']',
), '', $chunk);
$choices = explode(',', $chunk);
$replace = '<span class="correct answer user-answer">' . $choices[0] . '</span>';
$solution = str_replace($chunks[$position], $replace, $solution);
}
$content['answers'] = array(
'#markup' => '<div class="quiz-solution cloze-question">' . $solution . '</div>',
'#weight' => 5,
);
if (isset($this->node->learning_mode) && $this->node->learning_mode) {
$content['learning_mode'] = array(
'#markup' => '<div class="">' . t('Enabled to accept only the right answers.') . '</div>',
'#weight' => 5,
);
}
}
else {
$content['answers'] = array(
'#markup' => '<div class="quiz-answer-hidden">Answer hidden</div>',
'#weight' => 2,
);
}
return $content;
}