Problem/Motivation
When trying to add a question a fatal PHP error occurs:
Symfony\Component\Routing\Exception\RouteNotFoundException: Route "entity.quiz_question_type.add_form" does not exist. in Drupal\Core\Routing\RouteProvider->getRouteByName() (line 214 of core/lib/Drupal/Core/Routing/RouteProvider.php).
Steps to reproduce
Clean install of Drupal 11.3.3 and Quiz 7.0.4
Install Quiz module and all available Quiz Question modules:
- Quiz - Long answer
- Quiz - Matching question
- Quiz - Multichoice
- Quiz - Short answer
- Quiz - True false
Browse to /quiz-question/add and observe error.
Proposed resolution
This appears to have been caused by removal of the route in https://git.drupalcode.org/project/quiz/-/commit/7a917bc1067d3c83879c711...
Replacing this locally fixed the issue
Remaining tasks
Determine if this is appropriate fix, or if there is other underlying issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | quiz-3577129-add-quiz-question-type-add-form-route.patch | 2.29 KB | gwenweb |
Issue fork quiz-3577129
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
ben.hamelinThis is happening because of the core EntityController preparing the "no bundles" message for cases where there are no entity types available, in our case the Quiz Question Type:
from /core/lib/Drupal/Core/Entity/Controller/EntityController.php
One solution here would be to add the route and have it simply display a "You must enable at least one Quiz Question sub module" or similar, with a link to the Extend page. Additionally a note about how to extend the QuizQuestion class to create new question types.
Comment #4
phernand42 commentedRan into this issue too. Adding back the route fixes the RouteNotFoundException, but causes a regression of the issue that removed the route originally (which you linked to above):
https://www.drupal.org/project/quiz/issues/3545043
That issue was caused by BundleEntityFormBase not rendering the label/machine name fields, leaving only a Save button. The fix for that issue (removing the route) was more of a workaround then a true fix.
In addition to your suggestion, we could also try to:
1. Restore the add-form link (as shown in your diff)
2. Create src/Form/QuizQuestionTypeForm.php, a custom form class with explicit label and machine_name fields and update the form handler in the QuizQuestionType annotation to reference this new class instead of using Drupal\Core\Entity\BundleEntityFormBase directly. Using BundleEntityFormBase directly is what caused the empty form regression I believe. This pattern of using a dedicated form class is already used elsewhere in the module (QuizResultTypeForm and QuizTypeEntityForm), so QuizQuestionType was simply missing its equivalent.
Comment #5
gwenweb commentedI encountered this error on Drupal 11 with Quiz 7.1.0, when clicking the "Add quiz question" button at `/admin/quiz/questions`.
It looks like:
MR !70 proposes simply restoring the route, but I'm not sure that's enough — it might recreate the regression from #3545043.
One approach could be to introduce a dedicated `QuizQuestionTypeForm` class, following the same pattern already used for `QuizResultTypeForm` and `QuizTypeEntityForm` elsewhere in the module, and then re-add the `add-form` link.
I've attached a patch against Quiz 7.1.0 on Drupal 11. It tries this approach:
I'm not 100% sure this is the right direction, but it seems consistent with the existing patterns in the module. In the meantime, if anyone else is hitting this issue on the same setup and needs a quick workaround, this patch might help.
Comment #6
vm commentedThe reported issue persists in Drupal 11.4.0 and Quiz 7.1.1.
@gwenweb provided a patch that does seem to correct the issue raised and I am now able to add quiz questions. - Thank you.
Comment #7
smustgrave commentedCan #5 be turned to an MR please
Comment #8
smustgrave commentedComment #13
gwenweb commentedI've converted the patch from #5 into a merge request: !81
The approach follows the existing QuizResultTypeForm pattern — a dedicated QuizQuestionTypeForm class with explicit label and id fields, which avoids the regression from #3545043 where BundleEntityFormBase rendered only a Save button.
I've rebased it on the current 8.0.x. Happy to make any changes if needed!
Comment #14
gwenweb commentedComment #16
smustgrave commentedPerfect timing I'll include in the alpha release for 8.0.x later today!