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",
 *     }
  • Clear cache
  • Run \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 ✅ 6406
    • Add new test to validate exception message: Done ✅
    • Review

    User interface changes

    Before patch

    https://www.drupal.org/files/issues/2024-01-31/3418298-before-patch.png

    After patch

    https://www.drupal.org/files/issues/2024-01-31/3418298-after-patch.png

    API changes

    none

    Data model changes

    none

    Release notes snippet

    none

    Issue fork drupal-3418298

    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

    Akhil Babu created an issue. See original summary.

    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes

    akhil babu’s picture

    StatusFileSize
    new30.84 KB
    new33.42 KB
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Issue summary: View changes
    akhil babu’s picture

    Status: Active » Needs review

    Ready for review

    smustgrave’s picture

    @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

    smustgrave’s picture

    Issue tags: -Novice

    Actually don't think this is a novice issue though, so #13 is just an FYI

    akhil babu’s picture

    Noted! Thanks.

    kanchan bhogade’s picture

    Status: Needs review » Reviewed & tested by the community
    StatusFileSize
    new192.01 KB
    new196.47 KB

    Hi,
    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

    larowlan made their first commit to this issue’s fork.

    • larowlan committed 311c787f on 10.2.x
      Issue #3418298 by Akhil Babu, Kanchan Bhogade: Improve the exception...

    • larowlan committed 59f38cc3 on 11.x
      Issue #3418298 by Akhil Babu, Kanchan Bhogade: Improve the exception...
    larowlan’s picture

    Version: 11.x-dev » 10.2.x-dev
    Status: Reviewed & tested by the community » Fixed

    Committed to 11.x and backported to 10.2.x

    Thanks

    Status: Fixed » Closed (fixed)

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