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