diff --git a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php index d001c0f..cb6e473 100644 --- a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php +++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php @@ -57,7 +57,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Recursively also remove the entity type and the whole entity deletions // details element if nothing else is in there. if (isset($form['entity_deletes']['field_config']['#items']) && isset($form['entity_deletes']['field_config']['#items'][$this->entity->id()])) { - //unset($form['entity_deletes']['field_config']['#items'][$this->entity->id()]); + unset($form['entity_deletes']['field_config']['#items'][$this->entity->id()]); if (empty($form['entity_deletes']['field_config']['#items'])) { unset($form['entity_deletes']['field_config']); if (!Element::children($form['entity_deletes'])) { diff --git a/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php b/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php new file mode 100644 index 0000000..6fe6649 --- /dev/null +++ b/core/modules/field_ui/src/Tests/FieldUIDeleteTest.php @@ -0,0 +1,115 @@ +drupalPlaceBlock('system_breadcrumb_block'); + $this->drupalPlaceBlock('local_tasks_block'); + + // Create a test user. + $admin_user = $this->drupalCreateUser(array('access content', 'administer content types', 'administer node fields', 'administer node form display', 'administer node display', 'administer users', 'administer account settings', 'administer user display', 'bypass node access')); + $this->drupalLogin($admin_user); + } + + /** + * Tests that deletion removes field storages and fields as expected. + */ + function testDeleteField() { + $field_label = $this->randomMachineName(); + $field_name_input = 'test'; + $field_name = 'field_test'; + + // Create an additional node type. + $type_name1 = strtolower($this->randomMachineName(8)) . '_test'; + $type1 = $this->drupalCreateContentType(array('name' => $type_name1, 'type' => $type_name1)); + $type_name1 = $type1->id(); + + // Create a new field. + $bundle_path1 = 'admin/structure/types/manage/' . $type_name1; + $this->fieldUIAddNewField($bundle_path1, $field_name_input, $field_label); + + // Create an additional node type. + $type_name2 = strtolower($this->randomMachineName(8)) . '_test'; + $type2 = $this->drupalCreateContentType(array('name' => $type_name2, 'type' => $type_name2)); + $type_name2 = $type2->id(); + + // Add a field to the second node type. + $bundle_path2 = 'admin/structure/types/manage/' . $type_name2; + $this->fieldUIAddExistingField($bundle_path2, $field_name, $field_label); + + \Drupal::service('module_installer')->install(['views']); + ViewTestData::createTestViews(get_class($this), array('field_test_views')); + + // Check the config dependencies of the first field, the field storage must + // not be shown as being deleted yet. + $this->drupalGet("$bundle_path1/fields/node.$type_name1.$field_name/delete"); + $this->assertNoText(t('The listed configuration will be deleted.')); + $this->assertNoText(t('View')); + $this->assertNoText('test_view_field_delete'); + + // Delete the first field. + $this->fieldUIDeleteField($bundle_path1, "node.$type_name1.$field_name", $field_label, $type_name1); + + // Check that the field was deleted. + $this->assertNull(FieldConfig::loadByName('node', $type_name1, $field_name), 'Field was deleted.'); + // Check that the field storage was not deleted + $this->assertNotNull(FieldStorageConfig::loadByName('node', $field_name), 'Field storage was not deleted.'); + + // Check the config dependencies of the first field. + $this->drupalGet("$bundle_path2/fields/node.$type_name2.$field_name/delete"); + $this->assertText(t('The listed configuration will be deleted.')); + $this->assertText(t('View')); + $this->assertText('test_view_field_delete'); + + $xml = $this->cssSelect('#edit-entity-deletes'); + // Remove the wrapping HTML. + $this->assertIdentical(FALSE, strpos($xml[0]->asXml(), $field_label), 'The currently being deleted field is not shown in the entity deletions.'); + + // Delete the second field. + $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$field_name", $field_label, $type_name2); + + // Check that the field was deleted. + $this->assertNull(FieldConfig::loadByName('node', $type_name2, $field_name), 'Field was deleted.'); + // Check that the field storage was deleted too. + $this->assertNull(FieldStorageConfig::loadByName('node', $field_name), 'Field storage was deleted.'); + } + +} diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index fd049d1..f1db4d4 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -15,7 +15,6 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\simpletest\WebTestBase; use Drupal\taxonomy\Entity\Vocabulary; -use Drupal\views\Tests\ViewTestData; /** * Tests the Field UI "Manage fields" screen. @@ -32,7 +31,7 @@ class ManageFieldsTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'field_ui', 'field_test', 'taxonomy', 'image', 'block', 'field_test_views'); + public static $modules = array('node', 'field_ui', 'field_test', 'taxonomy', 'image', 'block'); /** * The ID of the custom content type created for testing. @@ -63,13 +62,6 @@ class ManageFieldsTest extends WebTestBase { protected $fieldName; /** - * Test views to enable - * - * @var string[] - */ - public static $testViews = array('test_view_field_delete'); - - /** * {@inheritdoc} */ protected function setUp() { @@ -90,7 +82,7 @@ protected function setUp() { // Create random field name with markup to test escaping. $this->fieldLabel = '' . $this->randomMachineName(8) . ''; - $this->fieldNameInput = 'test'; + $this->fieldNameInput = strtolower($this->randomMachineName(8)); $this->fieldName = 'field_'. $this->fieldNameInput; // Create Basic page and Article node types. @@ -453,9 +445,6 @@ function testDefaultValue() { * Tests that deletion removes field storages and fields as expected. */ function testDeleteField() { - - $this->fieldLabel = $this->randomMachineName(); - // Create a new field. $bundle_path1 = 'admin/structure/types/manage/' . $this->contentType; $this->fieldUIAddNewField($bundle_path1, $this->fieldNameInput, $this->fieldLabel); @@ -469,13 +458,6 @@ function testDeleteField() { $bundle_path2 = 'admin/structure/types/manage/' . $type_name2; $this->fieldUIAddExistingField($bundle_path2, $this->fieldName, $this->fieldLabel); - // Check the config dependencies of the first field, the field storage must - // not be shown as being deleted yet. - $this->drupalGet("$bundle_path1/fields/node.$this->contentType.$this->fieldName/delete"); - $this->assertNoText(t('The listed configuration will be deleted.')); - $this->assertNoText(t('View')); - $this->assertNoText('test_view_field_delete'); - // Delete the first field. $this->fieldUIDeleteField($bundle_path1, "node.$this->contentType.$this->fieldName", $this->fieldLabel, $this->contentType); @@ -484,19 +466,6 @@ function testDeleteField() { // Check that the field storage was not deleted $this->assertNotNull(FieldStorageConfig::loadByName('node', $this->fieldName), 'Field storage was not deleted.'); - \Drupal::service('module_installer')->install(['views']); - ViewTestData::createTestViews(get_class($this), array('field_test_views')); - - // Check the config dependencies of the first field. - $this->drupalGet("$bundle_path2/fields/node.$type_name2.$this->fieldName/delete"); - $this->assertText(t('The listed configuration will be deleted.')); - $this->assertText(t('View')); - $this->assertText('test_view_field_delete'); - - $xml = $this->cssSelect('#edit-entity-deletes'); - // Remove the wrapping HTML. - $this->assertIdentical(FALSE, strpos($xml[0]->asXml(), $this->fieldLabel), 'The currently being deleted field is not shown in the entity deletions.'); - // Delete the second field. $this->fieldUIDeleteField($bundle_path2, "node.$type_name2.$this->fieldName", $this->fieldLabel, $type_name2);