function entity_test_entity_type_alter in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_type_alter()
- 10 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_type_alter()
Implements hook_entity_type_alter().
File
- core/
modules/ system/ tests/ modules/ entity_test/ entity_test.module, line 86 - Test module for the entity API providing several entity types for testing.
Code
function entity_test_entity_type_alter(array &$entity_types) {
$state = \Drupal::state();
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
foreach (entity_test_entity_types() 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'));
}