You are here

public static function EntityTestUpdate::preCreate in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php \Drupal\entity_test_update\Entity\EntityTestUpdate::preCreate()
  2. 9 core/modules/system/tests/modules/entity_test_update/src/Entity/EntityTestUpdate.php \Drupal\entity_test_update\Entity\EntityTestUpdate::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_update/src/Entity/EntityTestUpdate.php, line 43

Class

EntityTestUpdate
Defines the test entity class for testing definition and schema updates.

Namespace

Drupal\entity_test_update\Entity

Code

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