You are here

public function GlobalReferenceManager::createEntityGlobalId in Content Synchronizer 8

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

Create GID.

Parameters

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

Return value

string The gid.

File

src/Service/GlobalReferenceManager.php, line 59

Class

GlobalReferenceManager
The global reference manager.

Namespace

Drupal\content_synchronizer\Service

Code

public function createEntityGlobalId(Entity $entity) {
  $gid = (int) (microtime(TRUE) * 100) . '.' . $entity
    ->getEntityTypeId() . '.' . $entity
    ->id();
  $data = [
    self::FIELD_GID => $gid,
    self::FIELD_ENTITY_ID => $entity
      ->id(),
    self::FIELD_ENTITY_TYPE => $entity
      ->getEntityTypeId(),
  ];
  \Drupal::database()
    ->insert(self::GID_TABLE_NAME)
    ->fields(array_keys($data))
    ->values($data)
    ->execute();
  return $gid;
}