diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index b8e2015..14e8b6c 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -886,10 +886,18 @@ function field_purge_batch($batch_size) { // field_purge_data() will need the field array. $field = field_info_field_by_id($instance['field_id']); // Retrieve some entities. - $results = $factory->get($entity_type) - ->condition('id:' . $field['id'] . '.deleted', 1) - ->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle) - ->range(0, $batch_size) + $query = $factory->get($entity_type) + ->condition('id:' . $field['id'] . '.deleted', 1); + // Special treatment is required for {taxonomy_term} table as there is no + // vocabulary_machine_name field in the {taxonomy_term} table. + if ($entity_type == 'taxonomy_term') { + $query->condition('vid', taxonomy_vocabulary_machine_name_load($ids->bundle)->vid); + } + else { + $query->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle); + } + + $results = $query->range(0, $batch_size) ->execute(); if ($results) { diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index 17d4bd7..705025e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -353,4 +353,27 @@ function testDuplicateFieldName() { $this->assertText(t('The machine-readable name is already in use. It must be unique.')); $this->assertUrl($url, array(), 'Stayed on the same page.'); } + + /** + * Tests that deletion removes fields and instances as expected for a term. + */ + function testDeleteTaxonomyField() { + // Create a new field. + $bundle_path = 'admin/structure/taxonomy/tags'; + $edit1 = array( + 'fields[_add_new_field][label]' => $this->field_label, + 'fields[_add_new_field][field_name]' => $this->field_name_input, + ); + $this->fieldUIAddNewField($bundle_path, $edit1); + + // Delete the field. + $this->fieldUIDeleteField($bundle_path, $this->field_name, $this->field_label, 'Tags'); + + // Reset the fields info. + field_info_cache_clear(); + // Check that the field instance was deleted. + $this->assertNull(field_info_instance('taxonomy_term', $this->field_name, 'tags'), 'Field instance was deleted.'); + // Check that the field was deleted too. + $this->assertNull(field_info_field($this->field_name), 'Field was deleted.'); + } }