Problem/Motivation
EntityTypeManager::getFormObject() will throw an exception if either the operation or its associated form class does not exist. The exception message will be in the format
''The "%s" entity type did not specify a "%s" form class.''
This message should be adjusted to include information about both scenarios.
Steps to reproduce
Case-1: Operation does not exist.
Run the following code to see the exception.
\Drupal::entityTypeManager()->getFormObject('node', 'invalid_operation');
Case-2: Form class does not exist.
Edit "handlers" annotation of node entity (core/modules/node/src/Entity/Node.php) and change class name of any one of the form handlers. eg:
* handlers = {
* "form" = {
* "default" = "Drupal\node\NonExistentClass",
* }
\Drupal::entityTypeManager()->getFormObject('node', 'default');In both cases, exception message would be in the format "The "%s" entity type did not specify a "%s" form class.".
Proposed resolution
Update the exception message.
When the operation not exist: "The "%s" entity type did not specify a "%s" form class.".
When the form class does not exist: "The "%s" form handler of the "%s" entity type specifies a non-existent class "%s"
Remaining tasks
Create a patch/MR: Done ✅ 6406Add new test to validate exception message: Done ✅- Review
User interface changes
Before patch

After patch

API changes
none
Data model changes
none
Release notes snippet
none
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | After_patch6406.png | 196.47 KB | kanchan bhogade |
| #16 | Before_patch6406.png | 192.01 KB | kanchan bhogade |
| #9 | 3418298-after-patch.png | 33.42 KB | akhil babu |
| #9 | 3418298-before-patch.png | 30.84 KB | akhil babu |
Issue fork drupal-3418298
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:
- 3418298-improve-the-exception
changes, plain diff MR !6406
Comments
Comment #2
akhil babuComment #3
akhil babuComment #4
akhil babuComment #5
akhil babuComment #6
akhil babuComment #7
akhil babuComment #9
akhil babuComment #10
akhil babuComment #11
akhil babuComment #12
akhil babuReady for review
Comment #13
smustgrave commented@Akhil Babu you opened a novice issue then worked on it. If you saw my comment on the parent issue #2820411: Improve the exception message when an entity handler class does not exist #35 noted that notice issues should be for new users. your post history shows that you can work on non novice issues.
Thanks
Comment #14
smustgrave commentedActually don't think this is a novice issue though, so #13 is just an FYI
Comment #15
akhil babuNoted! Thanks.
Comment #16
kanchan bhogade commentedHi,
I have verified and tested MR !6406 on Drupal version 11. x
MR applied successfully...
Followed testing steps as mentioned in the issue summary
Test Result:
The Error message is updated as per the mentioned in the Proposed solution.
Attaching screenshots for reference.
Moving to RTBC
Comment #20
larowlanCommitted to 11.x and backported to 10.2.x
Thanks