- Patch #783112 by alexpott, cha0s: deleting a taxonomy term through admin interface causes issues if terms were created on the node edit form.

merge-requests/26/head
Dries Buytaert 2010-04-30 12:52:10 +00:00
parent ec9e7ca47e
commit 7d83f7c893
2 changed files with 33 additions and 7 deletions

View File

@ -565,7 +565,6 @@ function taxonomy_term_delete($tid) {
return SAVED_DELETED;
}
/**
* Generate an array for rendering the given term.
*
@ -1018,13 +1017,15 @@ function taxonomy_implode_tags($tags, $vid = NULL) {
foreach ($tags as $tag) {
// Extract terms belonging to the vocabulary in question.
if (is_null($vid) || $tag->vid == $vid) {
// Make sure we have a completed loaded taxonomy term.
if (isset($tag->name)) {
// Commas and quotes in tag names are special cases, so encode 'em.
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
$tag->name = '"' . str_replace('"', '""', $tag->name) . '"';
}
// Commas and quotes in tag names are special cases, so encode 'em.
if (strpos($tag->name, ',') !== FALSE || strpos($tag->name, '"') !== FALSE) {
$tag->name = '"' . str_replace('"', '""', $tag->name) . '"';
$typed_tags[] = $tag->name;
}
$typed_tags[] = $tag->name;
}
}
return implode(', ', $typed_tags);
@ -1273,6 +1274,8 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
// Iterate through the fieldable entities again to attach the loaded term data.
foreach ($entities as $id => $entity) {
$rekey = FALSE;
foreach ($items[$id] as $delta => $item) {
// Check whether the taxonomy term field instance value could be loaded.
if (isset($terms[$item['tid']])) {
@ -1282,8 +1285,14 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
// Otherwise, unset the instance value, since the term does not exist.
else {
unset($items[$id][$delta]);
$rekey = TRUE;
}
}
if ($rekey) {
// Rekey the items array.
$items[$id] = array_values($items[$id]);
}
}
}
}

View File

@ -422,7 +422,7 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
/**
* Test term creation with a free-tagging vocabulary from the node form.
*/
function testNodeTermCreation() {
function testNodeTermCreationAndDeletion() {
// Enable tags in the vocabulary.
$instance = $this->instance;
$instance['widget'] = array('type' => 'taxonomy_autocomplete');
@ -446,6 +446,23 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
foreach ($terms as $term) {
$this->assertText($term, t('The term was saved and appears on the node page'));
}
// Get the created terms.
list($term1, $term2, $term3) = taxonomy_get_tree($this->vocabulary->vid);
// Delete one term.
$this->drupalPost('taxonomy/term/' . $term1->tid . '/edit', array(), t('Delete'));
$this->drupalPost(NULL, NULL, t('Delete'));
$term_names = array($term2->name, $term3->name);
// Get the node.
$node = $this->drupalGetNodeByTitle($edit["title"]);
$this->drupalGet('node/' . $node->nid);
foreach ($term_names as $term_name) {
$this->assertText($term_name, t('The term %name appears on the node page after one term %deleted was deleted', array('%name' => $term_name, '%deleted' => $term1->name)));
}
$this->assertNoText($term1->name, t('The deleted term %name does not appear on the node page.', array('%name' => $term1->name)));
}
/**