EntityStorageBase::create

public EntityStorageBase::create(array $values = array())

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

\Drupal\Core\Entity\EntityInterface A new entity object.

Overrides EntityStorageInterface::create

File

core/lib/Drupal/Core/Entity/EntityStorageBase.php, line 175

Class

EntityStorageBase
A base entity storage class.

Namespace

Drupal\Core\Entity

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public function create(array $values = array()) {
  $entity_class = $this->entityClass;
  $entity_class::preCreate($this, $values);
 
  // Assign a new UUID if there is none yet.
  if ($this->uuidKey && $this->uuidService && !isset($values[$this->uuidKey])) {
    $values[$this->uuidKey] = $this->uuidService->generate();
  }
 
  $entity = $this->doCreate($values);
  $entity->enforceIsNew();
 
  $entity->postCreate($this);
 
  // Modules might need to add or change the data initially held by the new
  // entity object, for instance to fill-in default values.
  $this->invokeHook('create', $entity);
 
  return $entity;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.