function hook_entity_type_alter

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_type_alter()
  2. 10 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_type_alter()
  3. 11.x core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_type_alter()

Alter the entity type definitions.

Modules may implement this hook to alter the information that defines an entity type. All properties that are available in \Drupal\Core\Entity\Annotation\EntityType and all the ones additionally provided by modules can be altered here.

Do not use this hook to add information to entity types, unless one of the following is true:

  • You are filling in default values.
  • You need to dynamically add information only in certain circumstances.
  • Your hook needs to run after hook_entity_type_build() implementations.

Use hook_entity_type_build() instead in all other cases.


\Drupal\Core\Entity\EntityTypeInterface[] $entity_types: An associative array of all entity type definitions, keyed by the entity type name. Passed by reference.

See also



Related topics

27 functions implement hook_entity_type_alter()

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

block_content_entity_type_alter in core/modules/block_content/block_content.module
Implements hook_entity_type_alter().
comment_test_entity_type_alter in core/modules/comment/tests/modules/comment_test/comment_test.module
Implements hook_entity_type_alter().
config_entity_static_cache_test_entity_type_alter in core/modules/config/tests/config_entity_static_cache_test/config_entity_static_cache_test.module
Implements hook_entity_type_alter().
config_test_entity_type_alter in core/modules/config/tests/config_test/config_test.module
Implements hook_entity_type_alter().
config_test_rest_entity_type_alter in core/modules/rest/tests/modules/config_test_rest/config_test_rest.module
Implements hook_entity_type_alter().

... See full list

1 invocation of hook_entity_type_alter()
KernelTestBaseTest::testSetUp in core/modules/simpletest/src/Tests/KernelTestBaseTest.php
Tests expected behavior of setUp().


core/lib/Drupal/Core/Entity/entity.api.php, line 816


function hook_entity_type_alter(array &$entity_types) {
    /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
    // Set the controller class for nodes to an alternate implementation of the
    // Drupal\Core\Entity\EntityStorageInterface interface.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.