function ContentEntityBase::create
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::create()
- 11.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::create()
Overrides EntityBase::create
File
-
core/
lib/ Drupal/ Core/ Entity/ ContentEntityBase.php, line 1161
Class
- ContentEntityBase
- Implements Entity Field API specific enhancements to the Entity class.
Namespace
Drupal\Core\EntityCode
public static function create(array $values = []) {
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$class_name = static::class;
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass($class_name));
// Always explicitly specify the bundle if the entity has a bundle class.
if ($storage instanceof BundleEntityStorageInterface && ($bundle = $storage->getBundleFromClass($class_name))) {
$values[$storage->getEntityType()
->getKey('bundle')] = $bundle;
}
return $storage->create($values);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.