entity_create($entity_type, array $values = array())
Constructs a new entity object, without permanently saving it.
\Drupal::entityTypeManager()->getStorage($entity_type)->create($values);
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.
\Drupal\Core\Entity\EntityInterface A new entity object.
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:
\Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
\Drupal\Core\Entity\EntityStorageInterface::create()
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