function ContentEntityStorageBase::create

Same name in other branches
  1. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::create()
  2. 11.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::create()

Overrides EntityStorageBase::create

2 calls to ContentEntityStorageBase::create()
ContentEntityStorageBase::createWithSampleValues in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Creates an entity with sample field values.
TermStorage::create in core/modules/taxonomy/src/TermStorage.php
1 method overrides ContentEntityStorageBase::create()
TermStorage::create in core/modules/taxonomy/src/TermStorage.php

File

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

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

public function create(array $values = []) {
    $bundle = $this->getBundleFromValues($values);
    $entity_class = $this->getEntityClass($bundle);
    // @todo Decide what to do if preCreate() tries to change the bundle.
    // @see https://www.drupal.org/project/drupal/issues/3230792
    $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;
}

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