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.
Motivation
There is currently no way (that I could find) to hook into to the deletion of a quiz result.
Proposed resolution
I have attached a patch in the first comment below that adds a hook_quiz_results_deleted that is called whenever quiz results are deleted.
Comment | File | Size | Author |
---|---|---|---|
#10 | quiz-hook_quiz_results_deleted-2039375-10.patch | 769 bytes | berenddeboer |
Comments
Comment #1
ben.denham CreditAttribution: ben.denham commentedPatch attached.
Comment #2
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedquiz_question_delete_result()
per result id being deletedComment #3
berenddeboer CreditAttribution: berenddeboer commentedUse case is for example if a trophy is awarded to a user when he does the quiz.
For debugging/error cases sometimes you want to delete the quiz, and then the trophy should disappear as well.
As every other Drupal entity has a hook on delete, quiz should have one too.
Comment #4
berenddeboer CreditAttribution: berenddeboer commentedComment #6
berenddeboer CreditAttribution: berenddeboer commentedComment #7
berenddeboer CreditAttribution: berenddeboer commentedHave added a reroll of this patch.
Comment #9
djdevinWe can put this in 4.x, but the hook in Quiz 7.x-5.x is hook_quiz_result_delete($quiz_result) so let's mirror that behavior.
Comment #10
berenddeboer CreditAttribution: berenddeboer at Xplain Hosting commentedReroll, and hook renamed as per #9.
Comment #11
berenddeboer CreditAttribution: berenddeboer at Xplain Hosting commentedComment #13
berenddeboer CreditAttribution: berenddeboer at Xplain Hosting commentedComment #14
djdevinCan you have it mirror the hook in the newer 5.x?
We use the Entity API in 5.x so it follows this format
https://api.drupal.org/api/drupal/modules!system!system.api.php/function...
Function would be hook_quiz_result_delete($quiz_result) (takes in a single result)
Comment #15
djdevin