You are here

public function EntityStorageBase::create in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/EntityStorageBase.php \Drupal\Core\Entity\EntityStorageBase::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

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

Overrides EntityStorageInterface::create

3 calls to EntityStorageBase::create()
FieldConfigStorage::loadByProperties in core/modules/field/src/FieldConfigStorage.php
Load entities by their property values.
FieldStorageConfigStorage::loadByProperties in core/modules/field/src/FieldStorageConfigStorage.php
Load entities by their property values.
TermStorage::create in core/modules/taxonomy/src/TermStorage.php
1 method overrides EntityStorageBase::create()
TermStorage::create in core/modules/taxonomy/src/TermStorage.php

File

core/lib/Drupal/Core/Entity/EntityStorageBase.php, line 180
Contains \Drupal\Core\Entity\EntityStorageBase.

Class

EntityStorageBase
A base entity storage class.

Namespace

Drupal\Core\Entity

Code

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;
}