function entity_test_entity_type_alter
Same name in other branches
- 9 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_type_alter()
- 8.9.x core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_type_alter()
- 11.x 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
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'));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.