Problem/Motivation
When disabling a Quiz question type module, existing Quizzes that use a question of that type are rendered unusable.
When taking the quiz (node/%quiz_menu/take/%question_number):
Fatal error: Call to a member function getAnsweringForm() on a non-object in /[...]/quiz/question_types/quiz_question/quiz_question.module on line 178
When managing questions in a quiz (node/%quiz_menu/quiz/questions):
Fatal error: Call to a member function isGraded() on a non-object in /[...]/quiz/quiz.admin.inc on line 911
To reproduce:
- Add a quiz with two question types
- Disable the second question type
- Take/manage the quiz
Proposed resolution
Option 1 Very fancy version:
Implement hook_node_type_delete()
and update every quiz to remove the questions of the node type
Option 2 Less fancy version:
Render a message 'Question is no longer available' when taking/managing a quiz with a missing question.
Remaining tasks
Write a patch
Review
User interface changes
Less fatal errors when taking/managing a quiz with missing questions
API changes
None
Comments
Comment #1
idebr CreditAttribution: idebr commentedComment #2
djdevinWe could add a question delete hook, but that might be very destructive considering you may have Quizzes or Quiz results that contain the question type, and it would mess up those results.
I'm for adding error conditions, blocking Quiz taking, and leaving it at that. We could do this by adding a QuizQuestionBroken/QuizQuestionBrokenResponse class then falling back to it. Some other modules do this to handle the fatal errors that would happen from instantiating classes that don't exist, but allowing the site to function.
We can modify _quiz_question_get_instance() and _quiz_question_response_get_instance() to return broken instances that serve as placeholders until the Quiz admin re-enables the question type or deletes the reference.
Some examples:
https://api.drupal.org/api/views/handlers!views_handler_area.inc/class/v...
http://cgit.drupalcode.org/course/tree/includes/course_object.core.inc?i...
http://drupalcontrib.org/api/drupal/contributions!entityreference!plugin...
Comment #3
idebr CreditAttribution: idebr commentedOh, that looks pretty elegant.
This is fixed in Drupal 8, modules that provide an entity type can no longer be disabled: #2278017: When a content entity type providing module is uninstalled, the entities are not fully deleted, leaving broken reference
Comment #4
djdevinMoved to #2923829: Deal with deleted questions