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);
}
doc_Drupal
2016-10-29 09:09:13
Comments
Leave a Comment

Please login to continue.