diff --git a/uuid.entity.inc b/uuid.entity.inc index 97f7178..dd69b3d 100644 --- a/uuid.entity.inc +++ b/uuid.entity.inc @@ -601,37 +601,46 @@ function entity_property_uuid_to_id(&$objects, $entity_type, $properties) { if (!is_array($properties)) { $properties = array($properties); } - $uuids = array(); - $values = array(); - $i = 0; - foreach ($things as &$object) { + foreach ($things as $k => &$object) { foreach ($properties as $property) { // This is probably an entity object. if (is_object($object) && isset($object->{$property})) { - $values[$i] = &$object->{$property}; + $value = &$object->{$property}; } // This is probably a field items array. elseif (is_array($object) && isset($object[$property])) { - $values[$i] = &$object[$property]; + $value = &$object[$property]; } else { - $i++; continue; } - if (uuid_is_valid($values[$i])) { - $uuids[] = $values[$i]; + if (uuid_is_valid($value)) { + $ids = entity_get_id_by_uuid($entity_type, array($value)); + } + else { + $ids = array(); + } + if (is_object($object)) { + if (isset($ids[$value])) { + $object->{$property} = $ids[$value]; + } + // The UUID lookup failed, remove the item. + else { + unset($object->{$property}); + } + } + elseif (is_array($object)) { + if (isset($ids[$value])) { + $object[$property] = $ids[$value]; + } + // The UUID lookup failed, remove the item. + elseif (is_array($objects)) { + unset($objects[$k]); + } + else { + unset($object[$property]); + } } - $i++; - } - } - $ids = entity_get_id_by_uuid($entity_type, $uuids); - foreach ($values as $i => $value) { - if (isset($ids[$value])) { - $values[$i] = $ids[$value]; - } - // The UUID lookup failed, remove the item. - else { - $values[$i] = NULL; } } }