function entity_test_entity_base_field_info_alter in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/entity_test/entity_test.module \entity_test_entity_base_field_info_alter()
Implements hook_entity_base_field_info_alter().
File
- core/
modules/ system/ tests/ modules/ entity_test/ entity_test.module, line 122 - Test module for the entity API providing several entity types for testing.
Code
function entity_test_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
$state = \Drupal::state();
if ($entity_type
->id() == 'entity_test_mulrev' && ($names = $state
->get('entity_test.field_definitions.translatable'))) {
foreach ($names as $name => $value) {
$fields[$name]
->setTranslatable($value);
}
}
if ($entity_type
->id() == 'node' && $state
->get('entity_test.node_remove_status_field')) {
unset($fields['status']);
}
if ($entity_type
->id() == 'entity_test' && $state
->get('entity_test.remove_name_field')) {
unset($fields['name']);
}
// In 8001 we are assuming that a new definition with multiple cardinality has
// been deployed.
// @todo Remove this if we end up using state definitions at runtime. See
// https://www.drupal.org/node/2554235.
if ($entity_type
->id() == 'entity_test' && $state
->get('entity_test.db_updates.entity_definition_updates') == 8001) {
$fields['user_id']
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
}
}