W3cubDocs

/Drupal 8

function entity_create

entity_create($entity_type, array $values = array())

Constructs a new entity object, without permanently saving it.

\Drupal::entityTypeManager()->getStorage($entity_type)->create($values);

Parameters

string $entity_type: The type of the entity.

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.

Deprecated

in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use The method overriding Entity::create() for the entity type, e.g. \Drupal\node\Entity\Node::create() if the entity type is known. If the entity type is variable, use the entity storage's create() method to construct a new entity:

See also

\Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()

\Drupal\Core\Entity\EntityStorageInterface::create()

File

core/includes/entity.inc, line 308
Entity API for handling entities like nodes or users.

Code

function entity_create($entity_type, array $values = array()) {
  return \Drupal::entityManager()
    ->getStorage($entity_type)
    ->create($values);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!entity.inc/function/entity_create/8.1.x