You are here

public static function EntityBase::create in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::create()

Constructs a new entity object, without permanently saving it.

Parameters

array $values: (optional) An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

Return value

static The entity object.

Overrides EntityInterface::create

1 call to EntityBase::create()
ConfigurableLanguage::createFromLangcode in core/modules/language/src/Entity/ConfigurableLanguage.php
Creates a configurable language object from a langcode.

File

core/lib/Drupal/Core/Entity/EntityBase.php, line 504

Class

EntityBase
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public static function create(array $values = []) {
  $entity_type_repository = \Drupal::service('entity_type.repository');
  $entity_type_manager = \Drupal::entityTypeManager();
  $storage = $entity_type_manager
    ->getStorage($entity_type_repository
    ->getEntityTypeFromClass(static::class));
  return $storage
    ->create($values);
}