Improve the exception message when an entity form class does not exist

Created on 31 January 2024, 11 months ago
Updated 3 March 2024, 10 months ago

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

    • : Done ✅ 6406
    • : Done ✅
    • Review

    User interface changes

    Before patch

    After patch

    API changes

    none

    Data model changes

    none

    Release notes snippet

    none

    🐛 Bug report
    Status

    Fixed

    Version

    10.2

    Component
    Entity 

    Last updated about 17 hours ago

    Created by

    🇮🇳India Akhil Babu Chengannur

    Live updates comments and jobs are added and updated live.
    Sign in to follow issues

    Merge Requests

    Comments & Activities

    Production build 0.71.5 2024