function EntityTestHooks::entityTypeAlter

Implements hook_entity_type_alter().

File

core/modules/system/tests/modules/entity_test/src/Hook/EntityTestHooks.php, line 38

Class

EntityTestHooks
Hook implementations for entity_test.

Namespace

Drupal\entity_test\Hook

Code

public function entityTypeAlter(array &$entity_types) : void {
    $state = \Drupal::state();
    
    /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
    foreach (EntityTestHelper::getEntityTypes() as $entity_type) {
        // Optionally specify a translation handler for testing translations.
        if ($state->get('entity_test.translation')) {
            $translation = $entity_types[$entity_type]->get('translation');
            $translation[$entity_type] = TRUE;
            $entity_types[$entity_type]->set('translation', $translation);
        }
    }
    // Allow entity_test_rev tests to override the entity type definition.
    $entity_types['entity_test_rev'] = $state->get('entity_test_rev.entity_type', $entity_types['entity_test_rev']);
    $entity_types['entity_test_revpub'] = $state->get('entity_test_revpub.entity_type', $entity_types['entity_test_revpub']);
    // Enable the entity_test_new only when needed.
    if (!$state->get('entity_test_new')) {
        unset($entity_types['entity_test_new']);
    }
    else {
        // Allow tests to override the entity type definition.
        $entity_types['entity_test_new'] = \Drupal::state()->get('entity_test_new.entity_type', $entity_types['entity_test_new']);
    }
    $entity_test_definition = $entity_types['entity_test'];
    $entity_test_definition->set('entity_keys', $state->get('entity_test.entity_keys', []) + $entity_test_definition->getKeys());
    // Allow tests to alter the permission granularity of entity_test_mul.
    $entity_types['entity_test_mul']->set('permission_granularity', \Drupal::state()->get('entity_test_mul.permission_granularity', 'entity_type'));
}

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