Hi,

Thanks for including formatters for Link and EntityReference :)
They work fine so far. However, I get the following warning when an EntityReference field is empty and not displayed at all:

Notice: Undefined variable: target_entities in textformatter_contrib_entityreference_field_create_list() (line 58 of .../textformatter/textformatter_contrib/textformatter_contrib.module).

Warning: Invalid argument supplied for foreach() in textformatter_contrib_entityreference_field_create_list() (line 58 of .../textformatter/textformatter_contrib/textformatter_contrib.module).

It seems that the formatter is called even though it shouldn't be displaying anything and the code doesn't handle this correctly. It's independent of which list type I choose and whether the items are linked to the entities or not.

In fact, adding a
if (isset($target_entities)) { ... }
block around the
foreach ($target_entities as $id => $entity) { ... }
block seems to fix it for me.

Thanks!

Comments

damiankloip’s picture

Yeah, that's a good point, That's a pretty easy fix and will do what we need. Will look @ now. Thanks lukasho!

damiankloip’s picture

Actually, we can just set the $target_entities variable as an array at the start of the function and we should be good.

damiankloip’s picture

Status: Active » Needs review

OK, fix committed, can you please confirm?

damiankloip’s picture

Status: Needs review » Fixed

This is working ok now, please re open if not!

Status: Fixed » Closed (fixed)

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

soulston’s picture

Status: Closed (fixed) » Active

Hi, I am getting this error when using 7.12 version:

Notice: Undefined variable: target_entities in textformatter_contrib_entityreference_field_create_list() (line 58 of /sites/all/modules/contrib/textformatter/textformatter_contrib/textformatter_contrib.module).
Warning: Invalid argument supplied for foreach() in textformatter_contrib_entityreference_field_create_list() (line 58 of /sites/all/modules/contrib/textformatter/textformatter_contrib/textformatter_contrib.module).

This is happening on a page that uses the formatters but where there is no content in those fields. I am also using display suite so I'm not certain if this is also a factor?

damiankloip’s picture

Status: Active » Fixed

This is fixed in the dev branch.

Status: Fixed » Closed (fixed)

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