You are here

public function GlobalReferenceManager::createGlobalEntityByImportingEntityAndGid in Content Synchronizer 8

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

Create GID from entity and gid.

Parameters

\Drupal\Core\Entity\Entity $entity: The entity.

string $gid: THe gid.

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

File

src/Service/GlobalReferenceManager.php, line 124

Class

GlobalReferenceManager
The global reference manager.

Namespace

Drupal\content_synchronizer\Service

Code

public function createGlobalEntityByImportingEntityAndGid(Entity $entity, $gid) {
  $data = [
    self::FIELD_GID => $gid,
    self::FIELD_ENTITY_ID => $entity
      ->id(),
    self::FIELD_ENTITY_TYPE => $entity
      ->getEntityTypeId(),
  ];
  try {
    \Drupal::database()
      ->insert(self::GID_TABLE_NAME)
      ->fields(array_keys($data))
      ->values($data)
      ->execute();
  } catch (\Exception $e) {

    // Mute exception...
  }
}