uuid.entity.inc 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. /**
  3. * @file
  4. * Entity related functions for UUID module.
  5. */
  6. /**
  7. * Entity UUID exception class.
  8. */
  9. class UuidEntityException extends Exception {}
  10. /**
  11. * Returns entity info for all supported core entities.
  12. *
  13. * @see uuid_entity_info()
  14. * @see uuid_schema_alter()
  15. * @see uuid_install()
  16. * @see uuid_uninstall()
  17. */
  18. function uuid_get_core_entity_info() {
  19. $info = array();
  20. $info['user'] = array(
  21. 'base table' => 'users',
  22. 'entity keys' => array(
  23. 'uuid' => 'uuid',
  24. ),
  25. );
  26. $info['node'] = array(
  27. 'base table' => 'node',
  28. 'revision table' => 'node_revision',
  29. 'entity keys' => array(
  30. 'uuid' => 'uuid',
  31. 'revision uuid' => 'vuuid',
  32. ),
  33. );
  34. if (module_exists('comment')) {
  35. $info['comment'] = array(
  36. 'base table' => 'comment',
  37. 'entity keys' => array(
  38. 'uuid' => 'uuid',
  39. ),
  40. );
  41. }
  42. if (module_exists('file')) {
  43. $info['file'] = array(
  44. 'base table' => 'file_managed',
  45. 'entity keys' => array(
  46. 'uuid' => 'uuid',
  47. ),
  48. );
  49. }
  50. if (module_exists('taxonomy')) {
  51. $info['taxonomy_term'] = array(
  52. 'base table' => 'taxonomy_term_data',
  53. 'entity keys' => array(
  54. 'uuid' => 'uuid',
  55. ),
  56. );
  57. }
  58. if (module_exists('field_collection')) {
  59. $info['field_collection_item'] = array(
  60. 'base table' => 'field_collection_item',
  61. 'entity keys' => array(
  62. 'uuid' => 'uuid',
  63. ),
  64. );
  65. }
  66. return $info;
  67. }
  68. /**
  69. * @defgroup uuid_entity_hooks UUID implementation of Entity API
  70. * @{
  71. */
  72. /**
  73. * Implements hook_entity_info_alter().
  74. *
  75. * @see uuid_core_entity_info()
  76. */
  77. function uuid_entity_info_alter(&$info) {
  78. foreach (uuid_get_core_entity_info() as $entity_type => $core_info) {
  79. $info[$entity_type]['uuid'] = TRUE;
  80. $info[$entity_type]['entity keys']['uuid'] = $core_info['entity keys']['uuid'];
  81. if (!empty($core_info['entity keys']['revision uuid'])) {
  82. $info[$entity_type]['entity keys']['revision uuid'] = $core_info['entity keys']['revision uuid'];
  83. }
  84. }
  85. }
  86. /**
  87. * Implements hook_entity_property_info_alter().
  88. *
  89. * This adds the UUID as an entity property for all UUID-enabled entities
  90. * which automatically gives us token and Rules integration.
  91. */
  92. function uuid_entity_property_info_alter(&$info) {
  93. foreach (entity_get_info() as $entity_type => $entity_info) {
  94. if (isset($entity_info['uuid']) && $entity_info['uuid'] == TRUE
  95. && !empty($entity_info['entity keys']['uuid'])
  96. && empty($info[$entity_type]['properties'][$entity_info['entity keys']['uuid']])) {
  97. $info[$entity_type]['properties'][$entity_info['entity keys']['uuid']] = array(
  98. 'label' => t('UUID'),
  99. 'type' => 'text',
  100. 'description' => t('The universally unique ID.'),
  101. 'schema field' => $entity_info['entity keys']['uuid'],
  102. );
  103. if (!empty($entity_info['entity keys']['revision uuid'])
  104. && empty($info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']])) {
  105. $info[$entity_type]['properties'][$entity_info['entity keys']['revision uuid']] = array(
  106. 'label' => t('Revision UUID'),
  107. 'type' => 'text',
  108. 'description' => t("The revision's universally unique ID."),
  109. 'schema field' => $entity_info['entity keys']['revision uuid'],
  110. );
  111. }
  112. }
  113. }
  114. }
  115. /**
  116. * Implements hook_entity_presave().
  117. *
  118. * This is where all UUID-enabled entities get their UUIDs.
  119. */
  120. function uuid_entity_presave($entity, $entity_type) {
  121. $info = entity_get_info($entity_type);
  122. if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
  123. $uuid_key = $info['entity keys']['uuid'];
  124. if (empty($entity->{$uuid_key})) {
  125. $entity->{$uuid_key} = uuid_generate();
  126. }
  127. if (!empty($info['entity keys']['revision uuid'])) {
  128. $vuuid_key = $info['entity keys']['revision uuid'];
  129. // If this entity comes from a remote environment and have a revision UUID
  130. // that exists locally we should not create a new revision. Because
  131. // otherwise revisions won't be tracked universally.
  132. // TODO: Move code dependent on the uuid_services module into it's own
  133. // implementation of hook_entity_presave().
  134. if (!empty($entity->uuid_services) && isset($entity->{$vuuid_key})) {
  135. $vuuid_exists = (bool) entity_get_id_by_uuid($entity_type, array($entity->{$vuuid_key}), TRUE);
  136. if ($vuuid_exists) {
  137. $entity->revision = FALSE;
  138. }
  139. }
  140. if ((isset($entity->revision) && $entity->revision == TRUE && empty($entity->uuid_services)) || empty($entity->{$vuuid_key})) {
  141. $entity->{$vuuid_key} = uuid_generate();
  142. }
  143. }
  144. }
  145. }
  146. /**
  147. * @} End of "UUID implementation of Entity API"
  148. */
  149. /**
  150. * @defgroup uuid_entity_support UUID support for Entity API
  151. * @{
  152. * Functions that extends the Entity API with UUID support.
  153. */
  154. /**
  155. * Load entities by their UUID, that only should containing UUID references.
  156. *
  157. * Optionally load revisions by their VUUID by passing it into $conditions.
  158. * Ex. $conditions['vuuid'][$vuuid]
  159. *
  160. * This function is mostly useful if you want to load an entity from the local
  161. * database that only should contain UUID references.
  162. *
  163. * @see entity_load()
  164. */
  165. function entity_uuid_load($entity_type, $uuids = array(), $conditions = array(), $reset = FALSE) {
  166. // Allow Revision UUID to be passed in $conditions and translate.
  167. $entity_info[$entity_type] = entity_get_info($entity_type);
  168. $revision_key = $entity_info[$entity_type]['entity keys']['revision'];
  169. if (isset($entity_info[$entity_type]['entity keys']['revision uuid'])) {
  170. $revision_uuid_key = $entity_info[$entity_type]['entity keys']['revision uuid'];
  171. }
  172. if (isset($revision_uuid_key) && isset($conditions[$revision_uuid_key])) {
  173. $revision_id = entity_get_id_by_uuid($entity_type, array($conditions[$revision_uuid_key]), TRUE);
  174. $conditions[$revision_key] = $revision_id[$conditions[$revision_uuid_key]];
  175. unset($conditions[$revision_uuid_key]);
  176. }
  177. $ids = entity_get_id_by_uuid($entity_type, $uuids);
  178. $results = entity_load($entity_type, $ids, $conditions, $reset);
  179. $entities = array();
  180. // We need to do this little magic here, because objects are passed by
  181. // reference. And because hook_entity_uuid_load() has the intention changing
  182. // primary properties and fields from local IDs to UUIDs it will also change
  183. // DrupalDefaultEntityController::entityCache by reference which is a static
  184. // cache of entities. And that is not something we want.
  185. foreach ($results as $key => $entity) {
  186. // This will avoid passing our loaded entities by reference.
  187. $entities[$key] = clone $entity;
  188. }
  189. entity_make_entity_universal($entity_type, $entities);
  190. return $entities;
  191. }
  192. /**
  193. * Helper function to make an entity universal (i.e. only global references).
  194. */
  195. function entity_make_entity_universal($entity_type, $entities) {
  196. // Let other modules transform local ID references to UUID references.
  197. if (!empty($entities)) {
  198. $hook = 'entity_uuid_load';
  199. foreach (module_implements($hook) as $module) {
  200. $function = $module . '_' . $hook;
  201. if (function_exists($function)) {
  202. $function($entities, $entity_type);
  203. }
  204. }
  205. }
  206. }
  207. /**
  208. * Permanently saves an entity by its UUID.
  209. *
  210. * This function depends on the Entity API module to provide the
  211. * 'entity_save()' function.
  212. *
  213. * This function is mostly useful if you want to save an entity into the local
  214. * database that only contains UUID references.
  215. *
  216. * @see entity_save()
  217. */
  218. function entity_uuid_save($entity_type, $entity) {
  219. // This function, and this function only, depends on the entity module.
  220. if (!module_exists('entity')) {
  221. throw new UuidEntityException(t('Calling %function requires the Entity API module (!link).', array('%function' => __FUNCTION__, '!link' => 'http://drupal.org/project/entity')));
  222. }
  223. $info = entity_get_info($entity_type);
  224. $uuid_key = $info['entity keys']['uuid'];
  225. if (empty($entity->{$uuid_key}) || !uuid_is_valid($entity->{$uuid_key})) {
  226. watchdog('Entity UUID', 'Attempted to save an entity with an invalid UUID', array(), WATCHDOG_ERROR);
  227. return FALSE;
  228. }
  229. // Falling back on the variable node_options_[type] is not something an API
  230. // function should take care of. With normal (non UUID) nodes this is dealt
  231. // with in the form submit handler, i.e. not in node_save().
  232. // But since using entity_uuid_save() usually means you're trying to manage
  233. // entities remotely we do respect this variable here to make it work as the
  234. // node form, but only if we explicitly haven't set $node->revision already.
  235. if ($entity_type == 'node' && !isset($entity->revision) && in_array('revision', variable_get('node_options_' . $entity->type, array()))) {
  236. $entity->revision = 1;
  237. }
  238. entity_make_entity_local($entity_type, $entity);
  239. // Save the entity.
  240. $result = entity_save($entity_type, $entity);
  241. $hook = 'entity_uuid_save';
  242. foreach (module_implements($hook) as $module) {
  243. $function = $module . '_' . $hook;
  244. if (function_exists($function)) {
  245. $function($entity, $entity_type);
  246. }
  247. }
  248. return $result;
  249. }
  250. /**
  251. * Helper function to make an entity local (i.e. only local references).
  252. */
  253. function entity_make_entity_local($entity_type, $entity) {
  254. $info = entity_get_info($entity_type);
  255. if (isset($info['uuid']) && $info['uuid'] == TRUE && !empty($info['entity keys']['uuid'])) {
  256. // Get the keys for local ID and UUID.
  257. $id_key = $info['entity keys']['id'];
  258. $uuid_key = $info['entity keys']['uuid'];
  259. // UUID entites must always provide a valid UUID when saving in order to do
  260. // the correct mapping between local and global IDs.
  261. if (empty($entity->{$uuid_key}) || !uuid_is_valid($entity->{$uuid_key})) {
  262. throw new UuidEntityException(t('Trying to save a @type entity with empty or invalid UUID.', array('@type' => $info['label'])));
  263. }
  264. // Fetch the local ID by its UUID.
  265. $ids = entity_get_id_by_uuid($entity_type, array($entity->{$uuid_key}));
  266. $id = reset($ids);
  267. // Set the correct local ID.
  268. if (empty($id)) {
  269. unset($entity->{$id_key});
  270. $entity->is_new = TRUE;
  271. }
  272. else {
  273. $entity->{$id_key} = $id;
  274. $entity->is_new = FALSE;
  275. }
  276. if (!empty($info['entity keys']['revision uuid'])) {
  277. // Get the keys for local revison ID and revision UUID.
  278. $vid_key = $info['entity keys']['revision'];
  279. $vuuid_key = $info['entity keys']['revision uuid'];
  280. $vid = NULL;
  281. // Fetch the local revision ID by its UUID.
  282. if (isset($entity->{$vuuid_key})) {
  283. // It's important to note that the revision UUID might be set here but
  284. // there might not exist a correspondant local revision ID in which case
  285. // we should unset the assigned revision ID to not confuse anyone with
  286. // revision IDs that might come from other environments.
  287. $vids = entity_get_id_by_uuid($entity_type, array($entity->{$vuuid_key}), TRUE);
  288. $vid = reset($vids);
  289. }
  290. if (empty($vid) && isset($entity->{$vid_key})) {
  291. unset($entity->{$vid_key});
  292. }
  293. elseif (!empty($vid)) {
  294. $entity->{$vid_key} = $vid;
  295. }
  296. // If the revision ID was unset before this (or just missing for some
  297. // reason) we fetch the current revision ID to build a better
  298. // representation of the node object we're working with.
  299. if ($entity_type == 'node' && !isset($entity->vid) && !$entity->is_new) {
  300. $entity->vid = db_select('node', 'n')
  301. ->condition('n.nid', $entity->nid)
  302. ->fields('n', array('vid'))
  303. ->execute()
  304. ->fetchField();
  305. }
  306. }
  307. // Let other modules transform UUID references to local ID references.
  308. $hook = 'entity_uuid_presave';
  309. foreach (module_implements($hook) as $module) {
  310. $function = $module . '_' . $hook;
  311. if (function_exists($function)) {
  312. $function($entity, $entity_type);
  313. }
  314. }
  315. }
  316. else {
  317. throw new UuidEntityException(t("Trying to operate on a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
  318. }
  319. }
  320. /**
  321. * Permanently delete the given entity by its UUID.
  322. *
  323. * This function depends on the Entity API module to provide the
  324. * 'entity_delete()' function.
  325. *
  326. * @see entity_delete()
  327. */
  328. function entity_uuid_delete($entity_type, $uuid) {
  329. // This function, and this function only, depends on the entity module.
  330. if (!module_exists('entity')) {
  331. throw new UuidEntityException(t('Calling %function requires the Entity API module (!link).', array('%function' => __FUNCTION__, '!link' => 'http://drupal.org/project/entity')));
  332. }
  333. $info = entity_get_info($entity_type);
  334. if (isset($info['uuid']) && $info['uuid'] == TRUE) {
  335. // Fetch the local ID by its UUID.
  336. $ids = entity_get_id_by_uuid($entity_type, array($uuid));
  337. $id = reset($ids);
  338. $entity = entity_load($entity_type, array($id));
  339. // Let other modules transform UUID references to local ID references.
  340. $hook = 'entity_uuid_delete';
  341. foreach (module_implements($hook) as $module) {
  342. $function = $module . '_' . $hook;
  343. if (function_exists($function)) {
  344. $function($entity, $entity_type);
  345. }
  346. }
  347. if (empty($entity)) {
  348. return FALSE;
  349. }
  350. // Delete the entity.
  351. return entity_delete($entity_type, $id);
  352. }
  353. else {
  354. throw new UuidEntityException(t("Trying to delete a @type entity, which doesn\'t support UUIDs.", array('@type' => $info['label'])));
  355. }
  356. }
  357. /**
  358. * Helper function that retrieves entity IDs by their UUIDs.
  359. *
  360. * @todo
  361. * Limit the query.
  362. *
  363. * @param string $entity_type
  364. * The entity type we should be dealing with.
  365. * @param array $uuids
  366. * List of UUIDs for which we should find their entity IDs. If $revision
  367. * is TRUE this should be revision UUIDs instead.
  368. * @param bool $revision
  369. * If TRUE the revision IDs is returned instead.
  370. *
  371. * @return array
  372. * List of entity IDs keyed by their UUIDs. If $revision is TRUE revision
  373. * IDs and UUIDs are returned instead.
  374. */
  375. function entity_get_id_by_uuid($entity_type, $uuids, $revision = FALSE) {
  376. if (empty($uuids)) {
  377. return array();
  378. }
  379. $cached_ids = entity_uuid_id_cache($entity_type, $uuids, $revision);
  380. if (count($cached_ids) == count($uuids)) {
  381. return $cached_ids;
  382. }
  383. $uuids = array_diff($uuids, $cached_ids);
  384. $info = entity_get_info($entity_type);
  385. // Some contrib entities has no support for UUID, let's skip them.
  386. if (empty($info['uuid'])) {
  387. return array();
  388. }
  389. // Find out what entity keys to use.
  390. if (!$revision) {
  391. $table = $info['base table'];
  392. $id_key = $info['entity keys']['id'];
  393. $uuid_key = $info['entity keys']['uuid'];
  394. }
  395. elseif (isset($info['revision table'])) {
  396. $table = $info['revision table'];
  397. $id_key = $info['entity keys']['revision'];
  398. $uuid_key = $info['entity keys']['revision uuid'];
  399. }
  400. // If we want revision IDs, but the entity doesn't support it. Return empty.
  401. else {
  402. return array();
  403. }
  404. // Get all UUIDs in one query.
  405. $result = db_select($table, 't')
  406. ->fields('t', array($uuid_key, $id_key))
  407. ->condition($uuid_key, array_values($uuids), 'IN')
  408. ->execute()
  409. ->fetchAllKeyed();
  410. $cache = &drupal_static('entity_uuid_id_cache', array());
  411. $cache[$entity_type][(int) $revision] += $result;
  412. return $result + $cached_ids;
  413. }
  414. /**
  415. * Helper caching function.
  416. */
  417. function entity_uuid_id_cache($entity_type, $ids, $revision) {
  418. $cache = &drupal_static(__FUNCTION__, array());
  419. if (empty($cache[$entity_type][(int) $revision])) {
  420. $cache[$entity_type][(int) $revision] = array();
  421. }
  422. $cached_ids = $cache[$entity_type][(int) $revision];
  423. return array_intersect_key($cached_ids, array_flip($ids));
  424. }
  425. /**
  426. * Helper function that retrieves UUIDs by their entity IDs.
  427. *
  428. * @todo
  429. * Limit the query.
  430. *
  431. * @param string $entity_type
  432. * The entity type we should be dealing with.
  433. * @param array $ids
  434. * List of entity IDs for which we should find their UUIDs. If $revision
  435. * is TRUE this should be revision IDs instead.
  436. * @param bool $revision
  437. * If TRUE the revision UUIDs is returned instead.
  438. *
  439. * @return array
  440. * List of entity UUIDs keyed by their IDs. If $revision is TRUE revision
  441. * IDs and UUIDs are returned instead.
  442. */
  443. function entity_get_uuid_by_id($entity_type, $ids, $revision = FALSE) {
  444. if (empty($ids)) {
  445. return array();
  446. }
  447. $cached_ids = array_flip(entity_uuid_id_cache($entity_type, $ids, $revision));
  448. if (count($cached_ids) == count($ids)) {
  449. return $cached_ids;
  450. }
  451. $ids = array_diff($ids, $cached_ids);
  452. $info = entity_get_info($entity_type);
  453. // Some contrib entities has no support for UUID, let's skip them.
  454. if (empty($info['uuid'])) {
  455. return array();
  456. }
  457. // Find out what entity keys to use.
  458. if (!$revision) {
  459. $table = $info['base table'];
  460. $id_key = $info['entity keys']['id'];
  461. $uuid_key = $info['entity keys']['uuid'];
  462. }
  463. elseif (isset($info['revision table'])) {
  464. $table = $info['revision table'];
  465. $id_key = $info['entity keys']['revision'];
  466. $uuid_key = $info['entity keys']['revision uuid'];
  467. }
  468. // If we want revision UUIDs, but the entity doesn't support it. Return empty.
  469. else {
  470. return array();
  471. }
  472. // Get all UUIDs in one query.
  473. $result = db_select($table, 't')
  474. ->fields('t', array($id_key, $uuid_key))
  475. ->condition($id_key, array_values($ids), 'IN')
  476. ->execute()
  477. ->fetchAllKeyed();
  478. $cache = &drupal_static('entity_uuid_id_cache', array());
  479. $cache[$entity_type][(int) $revision] += array_flip($result);
  480. return $result + $cached_ids;
  481. }
  482. /**
  483. * Helper function to change entity properties from ID to UUID.
  484. *
  485. * We never change user UID 0 or 1 to UUIDs. Those are low level user accounts
  486. * ("anonymous" and "root") that needs to be identified consistently across
  487. * any system.
  488. *
  489. * @todo
  490. * Add tests for this function.
  491. *
  492. * @param array $objects
  493. * List of objects that should get $properties changed. Can be either an
  494. * entity object or a field items array.
  495. * @param string $entity_type
  496. * The type of entity that all $properties refers to.
  497. * @param array $properties
  498. * An array of properties that should be changed. All properties must refer to
  499. * the same type of entity (the one referenced in $entity_type).
  500. */
  501. function entity_property_id_to_uuid(&$objects, $entity_type, $properties) {
  502. if (!is_array($objects)) {
  503. $things = array(&$objects);
  504. }
  505. else {
  506. $things = &$objects;
  507. }
  508. if (!is_array($properties)) {
  509. $properties = array($properties);
  510. }
  511. $ids = array();
  512. $values = array();
  513. $i = 0;
  514. foreach ($things as &$object) {
  515. foreach ($properties as $property) {
  516. // This is probably an entity object.
  517. if (is_object($object) && isset($object->{$property})) {
  518. $values[$i] = &$object->{$property};
  519. }
  520. // This is probably a field items array.
  521. elseif (is_array($object) && isset($object[$property])) {
  522. $values[$i] = &$object[$property];
  523. }
  524. else {
  525. $i++;
  526. continue;
  527. }
  528. if (!($entity_type == 'user' && ($values[$i] == 0 || $values[$i] == 1))) {
  529. $ids[] = $values[$i];
  530. }
  531. $i++;
  532. }
  533. }
  534. $uuids = entity_get_uuid_by_id($entity_type, $ids);
  535. foreach ($values as $i => $value) {
  536. if (isset($uuids[$value])) {
  537. $values[$i] = $uuids[$value];
  538. }
  539. }
  540. }
  541. /**
  542. * Helper function to change entity properties from UUID to ID.
  543. *
  544. * @todo
  545. * Add tests for this function.
  546. *
  547. * @param array $objects
  548. * List of objects that should get $properties changed. Can be either an
  549. * entity object or a field items array.
  550. * @param string $entity_type
  551. * The type of entity that all $properties refers to.
  552. * @param array $properties
  553. * An array of properties that should be changed. All properties must refer to
  554. * the same type of entity (the one referenced in $entity_type).
  555. */
  556. function entity_property_uuid_to_id(&$objects, $entity_type, $properties) {
  557. if (!is_array($objects)) {
  558. $things = array(&$objects);
  559. }
  560. else {
  561. $things = &$objects;
  562. }
  563. if (!is_array($properties)) {
  564. $properties = array($properties);
  565. }
  566. $uuids = array();
  567. $values = array();
  568. $i = 0;
  569. foreach ($things as &$object) {
  570. foreach ($properties as $property) {
  571. // This is probably an entity object.
  572. if (is_object($object) && isset($object->{$property})) {
  573. $values[$i] = &$object->{$property};
  574. }
  575. // This is probably a field items array.
  576. elseif (is_array($object) && isset($object[$property])) {
  577. $values[$i] = &$object[$property];
  578. }
  579. else {
  580. $i++;
  581. continue;
  582. }
  583. if (uuid_is_valid($values[$i])) {
  584. $uuids[] = $values[$i];
  585. }
  586. $i++;
  587. }
  588. }
  589. $ids = entity_get_id_by_uuid($entity_type, $uuids);
  590. foreach ($values as $i => $value) {
  591. if (isset($ids[$value])) {
  592. $values[$i] = $ids[$value];
  593. }
  594. }
  595. }
  596. /**
  597. * @} End of "UUID support for Entity API"
  598. */