You are here

function entity_property_uuid_to_id in Universally Unique IDentifier 7

Helper function to change entity properties from UUID to ID.

@todo Add tests for this function.

Parameters

array $objects: List of objects that should get $properties changed. Can be either an entity object or a field items array.

string $entity_type: The type of entity that all $properties refers to.

array $properties: An array of properties that should be changed. All properties must refer to the same type of entity (the one referenced in $entity_type).

Related topics

7 calls to entity_property_uuid_to_id()
comment_entity_uuid_presave in ./uuid.core.inc
Implements hook_entity_uuid_presave().
entityreference_field_uuid_presave in ./uuid.core.inc
Implements hook_field_uuid_presave().
file_entity_uuid_presave in ./uuid.core.inc
Implements hook_entity_uuid_presave().
file_field_uuid_presave in ./uuid.core.inc
Implements hook_field_uuid_presave().
node_entity_uuid_presave in ./uuid.core.inc
Implements hook_entity_uuid_presave().

... See full list

File

./uuid.entity.inc, line 594
Entity related functions for UUID module.

Code

function entity_property_uuid_to_id(&$objects, $entity_type, $properties) {
  if (!is_array($objects)) {
    $things = array(
      &$objects,
    );
  }
  else {
    $things =& $objects;
  }
  if (!is_array($properties)) {
    $properties = array(
      $properties,
    );
  }
  $uuids = array();
  $values = array();
  $i = 0;
  foreach ($things as &$object) {
    foreach ($properties as $property) {

      // This is probably an entity object.
      if (is_object($object) && isset($object->{$property})) {
        $values[$i] =& $object->{$property};
      }
      elseif (is_array($object) && isset($object[$property])) {
        $values[$i] =& $object[$property];
      }
      else {
        $i++;
        continue;
      }
      if (uuid_is_valid($values[$i])) {
        $uuids[] = $values[$i];
      }
      $i++;
    }
  }
  $ids = entity_get_id_by_uuid($entity_type, $uuids);
  foreach ($values as $i => $value) {
    if (isset($ids[$value])) {
      $values[$i] = $ids[$value];
    }
  }
}