You are here

public function GlobalReferenceManager::getEntityByGid in Content Synchronizer 8

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

Get the entity by is gid.

Parameters

string $gid: The gid.

Return value

\Drupal\Core\Entity\EntityInterface|null The entity.

1 call to GlobalReferenceManager::getEntityByGid()
GlobalReferenceManager::getExistingEntityByGidAndUuid in src/Service/GlobalReferenceManager.php
Return the entity by gid and uuid.

File

src/Service/GlobalReferenceManager.php, line 84

Class

GlobalReferenceManager
The global reference manager.

Namespace

Drupal\content_synchronizer\Service

Code

public function getEntityByGid($gid) {
  $query = \Drupal::database()
    ->select(self::GID_TABLE_NAME)
    ->fields(self::GID_TABLE_NAME, [
    self::FIELD_ENTITY_TYPE,
    self::FIELD_ENTITY_ID,
  ])
    ->condition(self::FIELD_GID, $gid);
  if ($result = $query
    ->execute()
    ->fetchAssoc()) {
    return \Drupal::entityTypeManager()
      ->getStorage($result[self::FIELD_ENTITY_TYPE])
      ->load($result[self::FIELD_ENTITY_ID]);
  }
  return NULL;
}