function EntitySchemaTestHooks::entityTypeAlter

Implements hook_entity_type_alter().

File

core/modules/system/tests/modules/entity_schema_test/src/Hook/EntitySchemaTestHooks.php, line 26

Class

EntitySchemaTestHooks
Hook implementations for entity_schema_test.

Namespace

Drupal\entity_schema_test\Hook

Code

public function entityTypeAlter(array &$entity_types) : void {
    // Allow a test to tell us whether or not to alter the entity type.
    if (\Drupal::state()->get('entity_schema_update')) {
        $entity_type = $entity_types['entity_test_update'];
        if ($entity_type instanceof ContentEntityTypeInterface) {
            $entity_type->set('translatable', TRUE);
            $entity_type->set('data_table', 'entity_test_update_data');
            // Update the keys with a revision ID.
            $keys = $entity_type->getKeys();
            $keys['revision'] = 'revision_id';
            $entity_type->set('entity_keys', $keys);
            $entity_type->setRevisionMetadataKey('revision_log_message', 'revision_log');
        }
    }
}

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