Using a token pattern such as [node:field-country] fails.

Notice: Undefined index: country in countries_entity_metadata_field_property_get() (line 426 of .../modules/contrib/countries/countries.module).
Notice: Trying to get property of non-object in countries_entity_metadata_field_property_get() (line 426 of .../modules/contrib/countries/countries.module).

All that is available on $entity in countries_entity_metadata_field_property_get() is the iso2 code but line 426 is looking for the cid.

Comments

webflo’s picture

Can't reproduce. Make sure you are using the latest dev version and please flush all caches. The entity controller has been changed recently.

langworthy’s picture

Here is a distribution that includes the latest dev of country.module and reproduces the problem.

webflo’s picture

Thanks for this awesome bug report :). I look into it soon.

webflo’s picture

Status: Active » Needs review
StatusFileSize
new1.45 KB

Ok here is a patch. I removed the hook_field_load() and replaced it with hook_field_prepare_view(). They "why" is well documented in hook_field_load().

Note that the changes made to the field values get cached by the field cache for subsequent loads. You should never use this hook to load fieldable entities, since this is likely to cause infinite recursions when hook_field_load() is run on those as well. Use hook_field_formatter_prepare_view() instead.

I think hook_field_prepare_view() is ok. Is there any objection?

langworthy’s picture

The patch in #4 fixes the problem.

As far as I can tell (but I may be wrong) hook_field_prepare_view() doesn't cache the field so I think we can remove the comments.

webflo’s picture

Status: Needs review » Fixed
Issue tags: +Needs change record

Yeah your are probably right. I committed the patch from #5. Thanks! Commit 8eafa77 on 7.x-2.x.

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