When Entity Reference is interacting with different modules, can produce the following error:

Notice : Undefined variable: element in entityreference_field_formatter_settings_form() (line 1141 in /sites/all/modules/entityreference/entityreference.module).

I found it is given because $element is display type is none of the expected ones. I have added a simple check to avoid returning $element if not set.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geoffreyr’s picture

This seems to be triggered when selecting Entity ID as the display type. Currently noticing this while I try and Formatter Field working with Paragraphs - there's no initialisation for $element taking place in this function.

geoffreyr’s picture

Status: Active » Needs review
FileSize
526 bytes

Here's a really tiny patch that should address the issue.

DamienMcKenna’s picture

Devin Carlson’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs review » Reviewed & tested by the community

This is very easy to run into while using the Entity Embed module.

The one-line patch in #2 applies cleanly to Entity Reference 7.x-1.x and ensures that $element is always defined. This is the same approach taken by the example implementation of hook_field_formatter_settings_form() in field_ui.api.php.

The last submitted patch, entityreference_2314339.patch, failed testing.

jenlampton’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
566 bytes

Patch in #2 didn't apply to 7.x-1.x-dev for me. Rerolled.

Status: Needs review » Needs work

The last submitted patch, 6: entityreference-undefined_variable-2495405-6.patch, failed testing.

jenlampton’s picture

Status: Needs work » Needs review
FileSize
526 bytes

Uploading previous patch to see if that passes tests, maybe my local branch is borked?

jenlampton’s picture

Status: Needs review » Reviewed & tested by the community

yeah, looks like it. setting back to RTBC.

Devin Carlson’s picture

Status: Reviewed & tested by the community » Fixed

Re-tested #2 and committed it to Entity Reference 7.x-1.x.

Status: Fixed » Closed (fixed)

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