Allow for more quiz styling

Created on 19 September 2022, over 2 years ago
Updated 14 August 2024, 4 months ago

Problem/Motivation

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

7.0

Component

Code - Quiz core

Created by

πŸ‡ΊπŸ‡ΈUnited States djdevin Philadelphia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡Έ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
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Actually appears to have been addressed in another ticket.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024