In entity_metadata_field_get_language() the default language is determined using the following:
$default_langcode = isset($entity->language) ? $entity->language : LANGUAGE_NONE;
However, if no language is set for the entity, $entity->language may be set to an empty string (''). This causes isset() to return TRUE and ends up returning an empty string if $langcode == LANGUAGE_NONE due to the following a few lines lower:
$langcode = ($langcode != LANGUAGE_NONE) ? field_valid_language($langcode, $default_langcode) : $default_langcode;
The line to determine the the default language should use !empty() instead, this will cover situations where it is not set as well as situations where it is set to NULL or an empty string.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | use-empty-for-entity-language-1703146-1.patch | 815 bytes | BassistJimmyJam |
Comments
Comment #1
BassistJimmyJam commentedPatch attached.
Comment #2
fagowell, I don't think the entity should have '' or FALSE as langcode, but still this makes our code more safe so let's do it.
Committed, thanks.
Comment #4
eclipsegc commentedThis bug alone has cost me literally hours to debug and trace. in Later php 5.3 versions (10+ I know for sure) $entity->language can come across set to NULL. At the very least this warrants a new point release of entity api. PLEASE :-) It'll start biting other people soon, I found and fixed this for myself and then came looking for an corresponding issue. Marking active again in the hopes of getting enough attention for a new release of the module. Thanks
Eclipse
Comment #5
mitchell commented#4: 1.0 Release can be tracked in #1647978: Entity API needs a 1.0 release as part of the Drupal.org D7 Upgrade Initiative.
Comment #5.0
mitchell commentedUpdated issue summary.