You are here

function _field_create_entity_from_ids in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/field/field.module \_field_create_entity_from_ids()

Assembles a partial entity structure with initial IDs.

Parameters

object $ids: An object with the properties entity_type (required), entity_id (required), revision_id (optional) and bundle (optional).

Return value

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

4 calls to _field_create_entity_from_ids()
FieldConfigEditForm::form in core/modules/field_ui/src/Form/FieldConfigEditForm.php
Gets the actual form array to be built.
FieldStorageConfigEditForm::form in core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
Gets the actual form array to be built.
SqlContentEntityStorage::readFieldItemsToPurge in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
Reads values to be purged for a single field.
TermEntityQueryTest::testTermEntityQuery in core/modules/taxonomy/tests/src/Kernel/TermEntityQueryTest.php
Tests that a basic taxonomy entity query works.

File

core/modules/field/field.module, line 274
Attach custom data fields to Drupal entities.

Code

function _field_create_entity_from_ids($ids) {
  $id_properties = [];
  $entity_type = \Drupal::entityTypeManager()
    ->getDefinition($ids->entity_type);
  if ($id_key = $entity_type
    ->getKey('id')) {
    $id_properties[$id_key] = $ids->entity_id;
  }
  if (isset($ids->revision_id) && ($revision_key = $entity_type
    ->getKey('revision'))) {
    $id_properties[$revision_key] = $ids->revision_id;
  }
  if (isset($ids->bundle) && ($bundle_key = $entity_type
    ->getKey('bundle'))) {
    $id_properties[$bundle_key] = $ids->bundle;
  }
  return \Drupal::entityTypeManager()
    ->getStorage($ids->entity_type)
    ->create($id_properties);
}