You are here

function entity_property_id_to_uuid in Universally Unique IDentifier 7

Helper function to change entity properties from ID to UUID.

We never change user UID 0 or 1 to UUIDs. Those are low level user accounts ("anonymous" and "root") that needs to be identified consistently across any system.

@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

6 calls to entity_property_id_to_uuid()
comment_entity_uuid_load in ./uuid.core.inc
Implements hook_entity_uuid_load().
entityreference_field_uuid_load in ./uuid.core.inc
Implements hook_field_uuid_load().
file_entity_uuid_load in ./uuid.core.inc
Implements hook_entity_uuid_load().
file_field_uuid_load in ./uuid.core.inc
Implements hook_field_uuid_load().
node_entity_uuid_load in ./uuid.core.inc
Implements hook_entity_uuid_load().

... See full list

File

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

Code

function entity_property_id_to_uuid(&$objects, $entity_type, $properties) {
  if (!is_array($objects)) {
    $things = array(
      &$objects,
    );
  }
  else {
    $things =& $objects;
  }
  if (!is_array($properties)) {
    $properties = array(
      $properties,
    );
  }
  $ids = 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 (!($entity_type == 'user' && ($values[$i] == 0 || $values[$i] == 1))) {
        $ids[] = $values[$i];
      }
      $i++;
    }
  }
  $uuids = entity_get_uuid_by_id($entity_type, $ids);
  foreach ($values as $i => $value) {
    if (isset($uuids[$value])) {
      $values[$i] = $uuids[$value];
    }
  }
}