function hook_entity_field_values_init
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_values_init()
- 8.9.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_values_init()
- 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_field_values_init()
Acts when initializing a fieldable entity object.
This hook runs after a new entity object or a new entity translation object has just been instantiated. It can be used to set initial values, e.g. to provide defaults.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity object.
See also
hook_ENTITY_TYPE_field_values_init()
Related topics
1 invocation of hook_entity_field_values_init()
- ContentEntityStorageBase::initFieldValues in core/
lib/ Drupal/ Core/ Entity/ ContentEntityStorageBase.php - Initializes field values.
File
-
core/
lib/ Drupal/ Core/ Entity/ entity.api.php, line 2218
Code
function hook_entity_field_values_init(\Drupal\Core\Entity\FieldableEntityInterface $entity) {
if ($entity instanceof \Drupal\Core\Entity\ContentEntityInterface && !$entity->foo->value) {
$entity->foo->value = 'some_initial_value';
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.