You are here

public function EntityShareEntityImport::setLocalEntityIds in Entity Share 7

Set the local entity ids.

Parameters

object $entity: Entity or sub entity to import.

1 call to EntityShareEntityImport::setLocalEntityIds()
EntityShareEntityImport::saveEntity in includes/entity_share.entity.import.inc
Save the entity using uuid if needed.

File

includes/entity_share.entity.import.inc, line 115
Class for handling Entity Import.

Class

EntityShareEntityImport
Manage general entity import.

Code

public function setLocalEntityIds($entity) {
  $entity_info = entity_get_info($entity->entity_type);
  $entity_id_info = $this
    ->getLocalEntityIds($entity);

  // Specific case of importing directly some entities
  // as main entity (taxonomy_term, ...).
  $context = array(
    'entity_info' => $entity_info,
    'entity_id_info' => $entity_id_info,
  );
  drupal_alter(self::HOOK_PREFIX . 'local_entities', $entity, $context);

  // Not available locally yet.
  if (!$entity_id_info) {

    // Clean exported entity id.
    $entity->{$entity_info['entity keys']['id']} = NULL;
  }
  if (!empty($entity_id_info['entity_id'])) {

    // Get local id.
    $entity->{$entity_info['entity keys']['id']} = $entity_id_info['entity_id'];
    if (!empty($entity_id_info['revision_id']) && isset($entity_info['entity keys']['revision'])) {
      $entity->{$entity_info['entity keys']['revision']} = $entity_id_info['revision_id'];
    }
    else {

      // If there is no revision_id or if it was not found on this site, set
      // this revision flag to true to create a new revision.
      $entity->revision = TRUE;

      // This uuid_services flag, indicate to uuid module no to overwrite
      // our vuuid with a new one.
      // @TODO Check uuid_entity_presave() for any update on uuid_services flag usage.
      $entity->uuid_services = TRUE;
    }
  }
}