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.

Issue fork quiz-3577129

Command icon 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

ben.hamelin created an issue. See original summary.

ben.hamelin’s picture

This 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

// Build the message shown when there are no bundles.
      $link_text = $this->t('Add a new @entity_type.', ['@entity_type' => $bundle_entity_type_label]);
      $link_route_name = 'entity.' . $bundle_entity_type->id() . '.add_form';
      $build['#add_bundle_message'] = $this->t('There is no @entity_type yet. @add_link', [
        '@entity_type' => $bundle_entity_type_label,
        '@add_link' => Link::createFromRoute($link_text, $link_route_name)->toString(),
      ]);

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.

phernand42’s picture

Ran 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.

gwenweb’s picture

Status: Active » Needs review
StatusFileSize
new2.29 KB

I 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:

  1. The `add-form` link was originally added in #3224280 to fix a "Route does not exist" error.
  2. It was then removed in #3545043 because using `BundleEntityFormBase` directly resulted in a broken form showing only a "Save" button, with no label or machine name fields.
  3. That removal seems to be what triggered the current issue.

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:

  • Adds `src/Form/QuizQuestionTypeForm.php` with explicit `label` and `id` (machine name) fields
  • Updates `QuizQuestionType.php` to use the new form class for `default`, `add` and `edit` handlers, and restores the `add-form` link

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.

vm’s picture

Version: 7.0.4 » 7.1.1

The 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.

smustgrave’s picture

Version: 7.1.1 » 8.0.x-dev

Can #5 be turned to an MR please

smustgrave’s picture

Status: Needs review » Needs work

gwenweb changed the visibility of the branch 7.0.x to active.

gwenweb changed the visibility of the branch 7.0.x to hidden.

gwenweb’s picture

I'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!

gwenweb’s picture

Status: Needs work » Needs review

  • smustgrave committed f752c9b9 on 8.0.x authored by gwenweb
    Issue #3577129 by gwenweb: Add QuizQuestionTypeForm to restore missing...
smustgrave’s picture

Status: Needs review » Fixed

Perfect timing I'll include in the alpha release for 8.0.x later today!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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