From 209a458cebaa5836d59187daed5c3e547dcfe085 Mon Sep 17 00:00:00 2001
From: dixon_ <dick.olsson@nodeone.se>
Date: Fri, 11 Mar 2011 22:06:36 +0100
Subject: [PATCH 1/2] Added bug fix and tests for it

---
 modules/taxonomy/taxonomy.admin.inc |    9 ++++++++-
 modules/taxonomy/taxonomy.test      |   31 +++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc
index 8498681..d9aa19c 100644
--- a/modules/taxonomy/taxonomy.admin.inc
+++ b/modules/taxonomy/taxonomy.admin.inc
@@ -860,7 +860,14 @@ function taxonomy_term_confirm_parents($form, &$form_state, $vocabulary) {
   $question = t('Set multiple term parents?');
   $description = '<p>' . t("Adding multiple parents to a term will cause the %vocabulary vocabulary to look for multiple parents on every term. Because multiple parents are not supported when using the drag and drop outline interface, drag and drop will be disabled if you enable this option. If you choose to have multiple parents, you will only be able to set parents by using the term edit form.", array('%vocabulary' => $vocabulary->name)) . '</p>';
   $description .= '<p>' . t("You may re-enable the drag and drop interface at any time by reducing multiple parents to a single parent for the terms in this vocabulary.") . '</p>';
-  return confirm_form($form, $question, drupal_get_destination(), $description, t('Set multiple parents'));
+
+  // Avoid the term's description getting overwritten when we call
+  // confirm_form().
+  $term_description = $form['description'];
+  $form = confirm_form($form, $question, drupal_get_destination(), $description, t('Set multiple parents'));
+  $form['confirm_form_description'] = $form['description'];
+  $form['description'] = $term_description;
+  return $form;
 }
 
 /**
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index a6ac332..d281272 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -727,6 +727,37 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
   }
 
   /**
+   * Test saving a term with multiple parents through the UI.
+   */
+  function testTermMultipleParentsInterface() {
+    // Add a new term to the vocabulary so that we can have multiple parents.
+    $parent = $this->createTerm($this->vocabulary);
+
+    // Add a new term with multiple parents.
+    $edit = array(
+      'name' => $this->randomName(12),
+      'description[value]' => $this->randomName(100),
+      'parent[]' => array(0, $parent->tid),
+    );
+    // Save the new term.
+    $this->drupalPost('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add', $edit, t('Save'));
+    // Submit the confirmation form for enabling multiple parents.
+    $this->drupalPost(NULL, NULL, t('Set multiple parents'));
+
+    // Check that the term was successfully created.
+    $terms = taxonomy_get_term_by_name($edit['name']);
+    $term = reset($terms);
+    $this->assertNotNull($term, t('Term found in database'));
+    $this->assertEqual($edit['name'], $term->name, t('Term name was successfully saved.'));
+    $this->assertEqual($edit['description[value]'], $term->description, t('Term description was successfully saved.'));
+    // Check that the parent tid is still there. The other parent (<root>) is
+    // not added by taxonomy_get_parents().
+    $parents = taxonomy_get_parents($term->tid);
+    $parent = reset($parents);
+    $this->assertEqual($edit['parent[]'][1], $parent->tid, t('Term parents was successfully saved.'));
+  }
+
+  /**
    * Test taxonomy_get_term_by_name().
    */
   function testTaxonomyGetTermByName() {
-- 
1.7.1


From f9c5889fc89da7ab4c1d55a50681709d78a67fc8 Mon Sep 17 00:00:00 2001
From: dixon_ <dick.olsson@nodeone.se>
Date: Fri, 11 Mar 2011 22:10:01 +0100
Subject: [PATCH 2/2] Fixed exception in confirm_form()

---
 modules/system/system.module |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/modules/system/system.module b/modules/system/system.module
index 6537671..905fa68 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -2826,11 +2826,14 @@ function confirm_form($form, $question, $path, $description = NULL, $yes = NULL,
   }
   elseif (is_array($path)) {
     $options = $path;
+    // To be sure that $options['path'] will be set.
+    if (isset($options['destination']) && !isset($options['path'])) {
+      $options['path'] = $options['destination'];
+    }
   }
   else {
     $options = array('path' => $path);
   }
-
   drupal_set_title($question, PASS_THROUGH);
 
   $form['#attributes']['class'][] = 'confirmation';
-- 
1.7.1

