public function EntityFormDisplayTest::testOnDependencyRemoval in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field_ui/tests/src/Kernel/EntityFormDisplayTest.php \Drupal\Tests\field_ui\Kernel\EntityFormDisplayTest::testOnDependencyRemoval()
- 9 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
->assertEquals('field_plugins_test_text_widget', $display
->getComponent($field_name)['type']);
// 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
->assertEquals('text_textfield', $display
->getComponent($field_name)['type']);
// 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));
}