Entity reference field produces fatal error: Error: Class name must be a valid object or a string in entity_get_controller()

Created on 29 January 2023, almost 2 years ago
Updated 10 February 2023, almost 2 years ago

Problem/Motivation

Trying to view an entity reference field throws a fatal error if the referenced target entity is disabled.

Steps to reproduce

This error happens with any entity type. For example, with comment:

  1. Create some articles and add some comments to them
  2. Create a new content type, e.g. test.
  3. Add an entity reference field to test, for example field_comment_ref. Set the target type to comment. Use a Select list as the widget
  4. Add content of type test. Type anything in the title. For the comment reference field, choose any of the listed comments in the select list
  5. Save and view your new content of type test

Then...

  1. Disable the Comment module
  2. View the content of type test you added above
  3. Error happens

I believe the solution may be to check if the entity type exists by checking entity_get_info() in entityreference_field_formatter_prepare_view() before calling entity_load().

πŸ› Bug report
Status

Needs work

Version

1.6

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States argiepiano

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

Comments & Activities

Production build 0.71.5 2024