By plach on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Issue links:
Description:
hook_entity_create() has been introduced to allow for altering the initial values of an entity object. The hook gets triggered by a call to entity_create(), thus it will run every time a new entity object is instantiated.
The hook may be used to populate default values or to provide initial values for the entity object in specific contexts:
<?php
/**
* Implements hook_entity_create().
*/
function mymodule_entity_create(EntityInterface $entity) {
// Customize the default value used for the entity title field.
if (empty($entity->title->value)) {
$entity->title->value = 'custom title';
}
}
?>
Impacts:
Module developers