Skip to content
Snippets Groups Projects
Commit dd8e4f2d authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1845372 by xjm, larowlan, Berdir, chx: Fixed Deleting a field from a...

Issue #1845372 by xjm, larowlan, Berdir, chx: Fixed Deleting a field from a non-node entity bundle results in an Entity Field Query Exception.
parent 4824c219
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -865,11 +865,14 @@ 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)
$query = $factory->get($entity_type)
->condition('id:' . $field['id'] . '.deleted', 1)
->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle)
->range(0, $batch_size)
->execute();
->range(0, $batch_size);
// If there's no bundle key, all results will have the same bundle.
if (!empty($info[$entity_type]['entity_keys']['bundle'])) {
$query->condition($info[$entity_type]['entity_keys']['bundle'], $ids->bundle);
}
$results = $query->execute();
if ($results) {
$entities = array();
......
......@@ -450,4 +450,27 @@ function testWidgetChange() {
$this->assertFieldByXPath("//select[@name='widget_type']", 'options_buttons');
}
/**
* 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.');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment