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

Created on 19 October 2016, about 8 years ago
Updated 20 February 2024, 10 months ago

Problem/Motivation

EntityTypeManager::getHandler() will throw an exception if either the handler or its associated class does not exist. The exception message will be in the format

''The "%s" entity type did not specify a %s handler.''

This message should be adjusted to include information about both scenarios.

Steps to reproduce

Case-1: Handler does not exist.
Run the following code to see the exception.

\Drupal::entityTypeManager()->getHandler('node', 'invalid_handler');

Case-2: Handler 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 handlers. eg:

 *   handlers = {
 *     "views_data" = "Drupal\node\InvalidClass",
  • Clear cache
  • Run \Drupal::entityTypeManager()->getHandler('node', 'views_data')
  • In both cases, exception message is in the format "The "%s" entity type did not specify a %s handler.".

    Proposed resolution

    Update the exception message.

    When handler does not exist: "The "%s" entity type did not specify a %s handler.".
    When handler class does not exist: "The %s handler of the "%s" entity type specifies a non-existent class "%s"

    Remaining tasks

    • Review

    User interface changes

    Before patch

    After patch

    API changes

    none

    Data model changes

    none

    Release notes snippet

    none

    ๐Ÿ› Bug report
    Status

    Fixed

    Version

    11.0 ๐Ÿ”ฅ

    Component
    Entityย  โ†’

    Last updated about 17 hours ago

    • Maintained by
    • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom @catch
    • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland @berdir
    • ๐Ÿ‡ฉ๐Ÿ‡ชGermany @hchonov
    Created by

    ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom joachim

    Live updates comments and jobs are added and updated live.
    • Novice

      It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

    Sign in to follow issues

    Merge Requests

    Comments & Activities

    Not all content is available!

    It's likely this issue predates Contrib.social: some issue and comment data are missing.

    Production build 0.71.5 2024