You are here

function entity_create in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/entity.inc \entity_create()

Constructs a new entity object, without permanently saving it.

\Drupal::entityManager()
  ->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\EntityManagerInterface::getStorage()

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

400 calls to entity_create()
ActionUnitTest::testDependencies in core/modules/system/src/Tests/Action/ActionUnitTest.php
Tests the dependency calculation of actions.
AggregatorTestBase::getFeedEditObject in core/modules/aggregator/src/Tests/AggregatorTestBase.php
Returns a randomly generated feed edit object.
BlockContentCacheTagsTest::createEntity in core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
Creates the entity to be tested.
BlockContentSaveTest::testImport in core/modules/block_content/src/Tests/BlockContentSaveTest.php
Checks whether custom block IDs are saved properly during an import.
BlockContentTestBase::createBlockContent in core/modules/block_content/src/Tests/BlockContentTestBase.php
Creates a custom block.

... See full list

5 string references to 'entity_create'
ConfigEntityStorageTest::testCreate in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@covers ::create @covers ::doCreate
ConfigEntityStorageTest::testCreateWithPredefinedUuid in core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityStorageTest.php
@covers ::create @covers ::doCreate
KeyValueEntityStorageTest::testCreate in core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@covers ::create @covers ::doCreate
KeyValueEntityStorageTest::testCreateWithoutUuidKey in core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@covers ::create @covers ::doCreate
KeyValueEntityStorageTest::testCreateWithPredefinedUuid in core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@covers ::create @covers ::doCreate

File

core/includes/entity.inc, line 300
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);
}