function EntityFieldTest::testFieldOverrideBundleField
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testFieldOverrideBundleField()
- 10 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testFieldOverrideBundleField()
- 11.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testFieldOverrideBundleField()
Tests creating a field override config for a bundle field.
See also
entity_test_entity_base_field_info_alter()
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityFieldTest.php, line 658
Class
- EntityFieldTest
- Tests the Entity Field API.
Namespace
Drupal\KernelTests\Core\EntityCode
public function testFieldOverrideBundleField() {
// First make sure the bundle field override in code, which is provided by
// the test entity works.
entity_test_create_bundle('some_test_bundle', 'Some test bundle', 'entity_test_field_override');
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'entity_test_field_override');
$this->assertEqual($field_definitions['name']->getDescription(), 'The default description.');
$this->assertNull($field_definitions['name']->getTargetBundle());
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
// Now create a config override of the bundle field.
$field_config = $field_definitions['name']->getConfig('some_test_bundle');
$field_config->setTranslatable(FALSE);
$field_config->save();
// Make sure both overrides are present.
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
$field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
$this->assertEqual($field_definitions['name']->getDescription(), 'Custom description.');
$this->assertEqual($field_definitions['name']->getTargetBundle(), 'some_test_bundle');
$this->assertFalse($field_definitions['name']->isTranslatable());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.