You are here

function hook_entity_create in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_create()

Acts when creating a new entity.

This hook runs after a new entity object has just been instantiated.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity object.

See also

hook_ENTITY_TYPE_create()

Related topics

2 functions implement hook_entity_create()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_crud_hook_test_entity_create in core/modules/system/tests/modules/entity_crud_hook_test/entity_crud_hook_test.module
Implements hook_entity_create().
jsonapi_entity_create in core/modules/jsonapi/jsonapi.module
Implements hook_entity_create().
2 invocations of hook_entity_create()
ConfigEntityStorage::_doCreateFromStorageRecord in core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php
Helps create a configuration entity from storage values.
EntityStorageBase::create in core/lib/Drupal/Core/Entity/EntityStorageBase.php
Constructs a new entity object, without permanently saving it.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 922
Hooks and documentation related to entities.

Code

function hook_entity_create(\Drupal\Core\Entity\EntityInterface $entity) {
  \Drupal::logger('example')
    ->info('Entity created: @label', [
    '@label' => $entity
      ->label(),
  ]);
}