- πΊπΈUnited States earthday47 New York
Hello, after working to customize the way quiz questions and results are templated and styled, I would strongly suggest using theme functions to render the final output of the quiz elements. Especially the results pages are hard to theme.
For example, I have overridden the QuizResultAnswerViewBuilder alterBuild() method and, along with some custom logic, returned this at the very end:
$build['quiz_result_answer'] = [ '#theme' => 'MYMODULE_quiz_result_answer', '#question' => $question_render, '#rows' => $rows, '#result_meta' => $result_meta, ]; return $build; }
Even simpler, some of the controller methods I just wrapped the output in a theme function:
namespace Drupal\MYMODULE_quiz_customizations\Controller; use Drupal\quiz\Controller\QuizQuestionController as OriginalQuizQuestionController; use Drupal\quiz\Entity\Quiz; class QuizQuestionController extends OriginalQuizQuestionController { /** * {@inheritdoc} */ function feedback(Quiz $quiz, $question_number) { $page = parent::feedback($quiz, $question_number); return [ '#theme' => 'MYMODULE_quiz_question_feedback', '#content' => $page['body'], ]; } /** * {@inheritdoc} */ function take(Quiz $quiz, $question_number) { $content = parent::take($quiz, $question_number); return [ '#theme' => 'MYMODULE_quiz_question_take', '#content' => $content, ]; } }
This let me add wrappers around the actual question component in a template file.
I can upload a patch if you would like to see more specifically what I'm proposing.
- πΊπΈUnited States smustgrave
100% lets try and land this for 7.0.x release
- Status changed to Fixed
5 months ago 10:35pm 31 July 2024 - πΊπΈUnited States smustgrave
Actually appears to have been addressed in another ticket.
Automatically closed - issue fixed for 2 weeks with no activity.