You are here

function entity_uuid_save in Universally Unique IDentifier 7

Permanently saves an entity by its UUID.

This function depends on the Entity API module to provide the 'entity_save()' function.

This function is mostly useful if you want to save an entity into the local database that only contains UUID references.

See also

entity_save()

Related topics

6 calls to entity_uuid_save()
UUIDCommentTestCase::testCommentCrud in ./uuid.test
Test CRUD on comments with UUID functions.
UUIDNodeTestCase::testNodeCrud in ./uuid.test
Tests CRUD on nodes with UUID functions.
UUIDTaxonomyTestCase::testTaxonomyCrud in ./uuid.test
Test CRUD on comments with UUID functions.
UUIDUserTestCase::testUserCrud in ./uuid.test
Test CRUD on users with UUID functions.
uuid_entities_rebuild in ./uuid.features.inc
Helper function to rebuild entities from a plan.

... See full list

1 string reference to 'entity_uuid_save'
uuid_hook_info in ./uuid.module
Implements hook_hook_info().

File

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

Code

function entity_uuid_save($entity_type, $entity) {

  // This function, and this function only, depends on the entity module.
  if (!module_exists('entity')) {
    throw new UuidEntityException(t('Calling %function requires the Entity API module (!link).', array(
      '%function' => __FUNCTION__,
      '!link' => 'http://drupal.org/project/entity',
    )));
  }
  $info = entity_get_info($entity_type);
  $uuid_key = $info['entity keys']['uuid'];
  if (empty($entity->{$uuid_key}) || !uuid_is_valid($entity->{$uuid_key})) {
    watchdog('Entity UUID', 'Attempted to save an entity with an invalid UUID', array(), WATCHDOG_ERROR);
    return FALSE;
  }

  // Falling back on the variable node_options_[type] is not something an API
  // function should take care of. With normal (non UUID) nodes this is dealt
  // with in the form submit handler, i.e. not in node_save().
  // But since using entity_uuid_save() usually means you're trying to manage
  // entities remotely we do respect this variable here to make it work as the
  // node form, but only if we explicitly haven't set $node->revision already.
  if ($entity_type == 'node' && !isset($entity->revision) && in_array('revision', variable_get('node_options_' . $entity->type, array()))) {
    $entity->revision = 1;
  }
  entity_make_entity_local($entity_type, $entity);

  // Save the entity.
  $result = entity_save($entity_type, $entity);
  $hook = 'entity_uuid_save';
  foreach (module_implements($hook) as $module) {
    $function = $module . '_' . $hook;
    if (function_exists($function)) {
      $function($entity, $entity_type);
    }
  }
  return $result;
}