You are here

public static function EntityTest::preCreate in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php \Drupal\entity_test\Entity\EntityTest::preCreate()

Changes the values of an entity before it is created.

Load defaults for example.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

mixed[] $values: An array of values to set, keyed by property name. If the entity type has bundles the bundle key has to be specified.

Overrides EntityBase::preCreate

File

core/modules/system/tests/modules/entity_test/src/Entity/EntityTest.php, line 59

Class

EntityTest
Defines the test entity class.

Namespace

Drupal\entity_test\Entity

Code

public static function preCreate(EntityStorageInterface $storage, array &$values) {
  parent::preCreate($storage, $values);
  if (empty($values['type'])) {
    $values['type'] = $storage
      ->getEntityTypeId();
  }
}