function ContentEntityStorageBase::createEntityFromIds

Same name and namespace in other branches
  1. main core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::createEntityFromIds()

Assembles a partial entity structure with initial IDs.

@internal

Parameters

array{entity_id: int|string, revision_id?: int|string, bundle?: string} $entity_identifiers: Array with the following keys:

  • entity_id (required),
  • revision_id (optional),
  • bundle (optional).

Return value

\Drupal\Core\Entity\ContentEntityInterface An entity object, initialized with the provided IDs.

1 call to ContentEntityStorageBase::createEntityFromIds()
SqlContentEntityStorage::readFieldItemsToPurge in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
Reads values to be purged for a single field.

File

core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php, line 1535

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function createEntityFromIds(array $entity_identifiers) : ContentEntityInterface {
  $id_properties = [];
  if ($id_key = $this->entityType
    ->getKey('id')) {
    $id_properties[$id_key] = $entity_identifiers['entity_id'];
  }
  if (isset($entity_identifiers['revision_id']) && $revision_key = $this->entityType
    ->getKey('revision')) {
    $id_properties[$revision_key] = $entity_identifiers['revision_id'];
  }
  if (isset($entity_identifiers['bundle']) && $bundle_key = $this->entityType
    ->getKey('bundle')) {
    $id_properties[$bundle_key] = $entity_identifiers['bundle'];
  }
  return $this->create($id_properties);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.