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().

Comments

argiepiano created an issue. See original summary.

joseph.olstad’s picture

joseph.olstad’s picture

Version: 7.x-1.5 » 7.x-1.6
joseph.olstad’s picture

Actually, looks like a new issue, if you propose a patch I'll review.

See release notes for ideas.

https://www.drupal.org/project/entityreference/releases/7.x-1.6

joseph.olstad’s picture

Priority: Normal » Minor
Status: Active » Needs work

putting this to minor, should be an infrequently observed issue, with that said, could definately be improved. I will review patches.