function EntityFormDisplayTest::testOnDependencyRemoval
Same name in other branches
- 9 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testOnDependencyRemoval()
- 10 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testOnDependencyRemoval()
- 11.x core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testOnDependencyRemoval()
Tests \Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval().
File
-
core/
modules/ field_ui/ tests/ src/ Kernel/ EntityFormDisplayTest.php, line 244
Class
- EntityFormDisplayTest
- Tests the entity display configuration entities.
Namespace
Drupal\Tests\field_ui\KernelCode
public function testOnDependencyRemoval() {
$this->enableModules([
'field_plugins_test',
]);
$field_name = 'test_field';
// Create a field.
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'type' => 'text',
]);
$field_storage->save();
$field = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
]);
$field->save();
EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
])->setComponent($field_name, [
'type' => 'field_plugins_test_text_widget',
])
->save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
// Check the component exists and is of the correct type.
$display = $display_repository->getFormDisplay('entity_test', 'entity_test');
$this->assertEqual($display->getComponent($field_name)['type'], 'field_plugins_test_text_widget');
// Removing the field_plugins_test module should change the component to use
// the default widget for test fields.
\Drupal::service('config.manager')->uninstall('module', 'field_plugins_test');
$display = $display_repository->getFormDisplay('entity_test', 'entity_test');
$this->assertEqual($display->getComponent($field_name)['type'], 'text_textfield');
// Removing the text module should remove the field from the form display.
\Drupal::service('config.manager')->uninstall('module', 'text');
$display = $display_repository->getFormDisplay('entity_test', 'entity_test');
$this->assertNull($display->getComponent($field_name));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.