- ๐ฎ๐ณIndia aditi saraf
Aditi Saraf โ made their first commit to this issueโs fork.
- ๐ฌ๐งUnited Kingdom longwave UK
Should we add a runtime assertion so anyone who makes this mistake gets a better error message?
- Assigned to aditi saraf
- Issue was unassigned.
- ๐ฎ๐ณIndia aditi saraf
@Joachim i am not able to reproduce this issue .
- ๐ฌ๐งUnited Kingdom joachim
I can still see the call to setModuleHandler in getFormObject(), which AFAICT isn't in FormBase.
- ๐ง๐ชBelgium xdequinze Brussels
@joachim, I am trying to understand the issue. Would you like to provide more details about it ? What are you trying to achieve ?
- ๐ฌ๐งUnited Kingdom joachim
If you define a route that uses an entity form, you use '_entity_form' in the route definition, and set a form class name as a value.
If your form class inherits the standard form class base, it crashes.
The docs for _entity_form in entity.api.php should say that you need to use a specific base class.
- First commit to issue fork.
- Merge request !12306Issue #3205577: Throw exception when an entity types form class doesn't implement EntityFormInterface โ (Open) created by acbramley
- Status changed to Needs review
3 months ago 5:39am 4 June 2025 - ๐ฆ๐บAustralia acbramley
Encountered this in โจ Allow vocabulary overview form class to be overridden Active and I agree we should improve this by throwing an error. I don't think this is novice based on the test coverage required.
- ๐ฌ๐งUnited Kingdom joachim
The check in core/lib/Drupal/Core/Entity/EntityTypeManager.php is not what I was expecting, and it's a good idea because it'll give a better error for people who use the wrong sort of form class as an entity handler.
But it won't catch the case where you use _entity_form directly in a route definition.
- ๐ฆ๐บAustralia acbramley
It does catch it, try adding this (mimics VocabularyRouteProvider::getOverviewPageRoute)
entity.vocab.overview: path: '/admin/structure/taxonomy/manage/{taxonomy_vocabulary}/overview2' defaults: _entity_form: 'taxonomy_vocabulary.overview' _title: 'Test' requirements: _entity_access: 'taxonomy_vocabulary.access taxonomy overview' options: _admin_route: TRUE parameters: taxonomy_vocabulary: with_config_overrides: TRUE
EntityRouteEnhancer::enhanceEntityForm
sets the controller tocontroller.entity_form:getContentResult
based on the_entity_form
default. That callsHtmlEntityFormController::getFormObject
which callsEntityTypeManager::getFormObject
The
_entity_form
route default is tied directly to the form handler class. - ๐ฌ๐งUnited Kingdom joachim
Ah, I hadn't spotted that!
The exception message will be wrong in that scenario though:
> 'The "%s" form handler of the "%s" entity type specifies a class "%s" that does not extend "%s".'
because it's not been caused by a form handler.
- ๐ฆ๐บAustralia acbramley
because it's not been caused by a form handler.
The form handler is the second part of the _entity_form string, e.g the example above maps to the overview form handler of the Vocabulary entity type.
I also wondered if we should just through the error when the entity type is parsed, but technically at the moment you can have form handlers that aren't tied to routes and therefore don't need to implement the interface.
In Vocabulary's case it had the form handler but the route for it isn't using the _entity_form method and afaik form handlers aren't used in many other ways?
We also might need to throw a deprecation first before a full exception so sites don't blow up? - ๐ฌ๐งUnited Kingdom joachim
> I also wondered if we should just through the error when the entity type is parsed, but technically at the moment you can have form handlers that aren't tied to routes and therefore don't need to implement the interface.
In that scenario, is there something like DefaultHtmlRouteProvider setting up the route?
Or are there entity types that specify a form handler for a form that's only shown embedded in something else?