Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Question type may need to know when user retry a question — change question details, log incorrects, change max score, …
For sure, the module can alter the form to add custom element validate, … but it's not nice as include the logic in handler class.
Proposed resolution
Add new item to contract: QuizResponse(Interface)::onRepeatUntilCorrect()
/**
* Method is called when user retry.
* @param Result $result
* @param array $element
*/
public function onRepeatUntiCorrect(Result $result, array &$element);
Comments
Comment #1
djdevinThis will already happen in #2391723: Normalize data storage for question responses. It won't be Question-specific, so I don't think the question types need to know about it. The logging of answers will happen the normal way that a Question stores the response. Will probably get into 5.x as well.
The build on last attempt functionality is already able to clone question responses regardless of the question type, so we will just keep writing question responses for each attempt.
Comment #2
thehong CreditAttribution: thehong commentedMy question type would like to do somethings:
- Log things, yeah just for this question type
- Says something to taker when they retry (until correct)
- Change the logic to display question on retry
- …
I think it's much easier with this event supporting.
Comment #3
djdevinDon't we already have that, since you have the entity operation for quiz_result_answer?
I'm using this in production right now to do that sort of thing.
Comment #4
thehong CreditAttribution: thehong commentedOk, you decide it. But I want draft the code with & without this:
Comment #5
djdevinSure you can just submit a patch and we will check it out.
The other thing to keep in mind is that if you want to build custom one off events like this you are going to lose out on things like Rules and stuff :(
Comment #6
djdevinInstead of the custom solution proposed here, this was done in an Entity compatible way in #2391723: Normalize data storage for question responses