You are here

public function GlobalReferenceManager::getExistingEntityByGidAndUuid in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Service/GlobalReferenceManager.php \Drupal\content_synchronizer\Service\GlobalReferenceManager::getExistingEntityByGidAndUuid()
  2. 3.x src/Service/GlobalReferenceManager.php \Drupal\content_synchronizer\Service\GlobalReferenceManager::getExistingEntityByGidAndUuid()

Return the entity by gid and uuid.

File

src/Service/GlobalReferenceManager.php, line 155

Class

GlobalReferenceManager
The global reference manager.

Namespace

Drupal\content_synchronizer\Service

Code

public function getExistingEntityByGidAndUuid($gid, $uuid) {

  // Load by gid for already imported or exported data :
  if ($existing = $this
    ->getEntityByGid($gid)) {
    return $existing;
  }

  // Load by uuid :
  try {
    $entityType = $this
      ->getEntityTypeFromGid($gid);
    $query = \Drupal::entityQuery($entityType)
      ->condition('uuid', $uuid);
    $result = $query
      ->execute();
    if (!empty($result)) {

      // Get the entity.
      $entity = \Drupal::entityTypeManager()
        ->getStorage($entityType)
        ->load(reset($result));

      // Create the global reference association.
      $this
        ->createGlobalEntityByImportingEntityAndGid($entity, $gid);
      return $entity;
    }
  } catch (\Exception $e) {

    // Mute exception.
  }
  return NULL;
}