function ContentEntityStorageBase::doCreate

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doCreate()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doCreate()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php \Drupal\Core\Entity\ContentEntityStorageBase::doCreate()

Overrides EntityStorageBase::doCreate

1 call to ContentEntityStorageBase::doCreate()
ContentEntityStorageBase::create in core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
Constructs a new entity object, without permanently saving it.

File

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

Class

ContentEntityStorageBase
Base class for content entity storage handlers.

Namespace

Drupal\Core\Entity

Code

protected function doCreate(array $values) {
    $bundle = $this->getBundleFromValues($values);
    if ($this->bundleKey && !$bundle) {
        throw new EntityStorageException('Missing bundle for entity type ' . $this->entityTypeId);
    }
    $entity_class = $this->getEntityClass($bundle);
    $entity = new $entity_class([], $this->entityTypeId, $bundle);
    $this->initFieldValues($entity, $values);
    return $entity;
}

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