From 32d9af49169f47cbaad8940b284153dffb664afe Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 6 Dec 2005 12:20:24 +0000
Subject: [PATCH] - Patch #39598 by Gerhard: fixed problem with taxonomy terms
 not being selected.

---
 modules/forum.module             | 7 ++-----
 modules/forum/forum.module       | 7 ++-----
 modules/taxonomy.module          | 5 +++--
 modules/taxonomy/taxonomy.module | 5 +++--
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/modules/forum.module b/modules/forum.module
index 2790f5be7f66..7e36b4087d69 100644
--- a/modules/forum.module
+++ b/modules/forum.module
@@ -592,12 +592,9 @@ function forum_form(&$node) {
     $node->taxonomy[] = arg(3);
   }
   else {
-    $node->taxonomy = array($node->tid);
-  }
-
-  if ($node->nid) {
+    $forum_terms = taxonomy_node_get_terms_by_vocabulary(_forum_get_vid(), $node->nid);
     // if editing, give option to leave shadows
-    $shadow = (count(taxonomy_node_get_terms($node->nid)) > 1);
+    $shadow = (count($forum_terms) > 1);
     $form['shadow'] = array('#type' => 'checkbox', '#title' => t('Leave shadow copy'), '#default_value' => $shadow, '#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.'));
   }
 
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 2790f5be7f66..7e36b4087d69 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -592,12 +592,9 @@ function forum_form(&$node) {
     $node->taxonomy[] = arg(3);
   }
   else {
-    $node->taxonomy = array($node->tid);
-  }
-
-  if ($node->nid) {
+    $forum_terms = taxonomy_node_get_terms_by_vocabulary(_forum_get_vid(), $node->nid);
     // if editing, give option to leave shadows
-    $shadow = (count(taxonomy_node_get_terms($node->nid)) > 1);
+    $shadow = (count($forum_terms) > 1);
     $form['shadow'] = array('#type' => 'checkbox', '#title' => t('Leave shadow copy'), '#default_value' => $shadow, '#description' => t('If you move this topic, you can leave a link in the old forum to the new forum.'));
   }
 
diff --git a/modules/taxonomy.module b/modules/taxonomy.module
index a3f3a796d3cc..5b4bd3627d76 100644
--- a/modules/taxonomy.module
+++ b/modules/taxonomy.module
@@ -498,7 +498,7 @@ function taxonomy_form_alter($form_id, &$form) {
   if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
     $node = $form['#node'];
 
-    if (!array_key_exists('taxonomy', $node)) {
+    if (!isset($node->taxonomy)) {
       if ($node->nid) {
         $terms = taxonomy_node_get_terms($node->nid);
       }
@@ -531,7 +531,8 @@ function taxonomy_form_alter($form_id, &$form) {
         $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield', '#default_value' => $typed_string, '#maxlength' => 100, '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid, '#required' => $vocabulary->required, '#title' => $vocabulary->name, '#description' => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'));
       }
       else {
-        $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms);
+        $ntterms = isset($node->taxonomy) ? $terms : array_keys($terms);
+
         $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, 'taxonomy');
       }
     }
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index a3f3a796d3cc..5b4bd3627d76 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -498,7 +498,7 @@ function taxonomy_form_alter($form_id, &$form) {
   if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
     $node = $form['#node'];
 
-    if (!array_key_exists('taxonomy', $node)) {
+    if (!isset($node->taxonomy)) {
       if ($node->nid) {
         $terms = taxonomy_node_get_terms($node->nid);
       }
@@ -531,7 +531,8 @@ function taxonomy_form_alter($form_id, &$form) {
         $form['taxonomy']['tags'][$vocabulary->vid] = array('#type' => 'textfield', '#default_value' => $typed_string, '#maxlength' => 100, '#autocomplete_path' => 'taxonomy/autocomplete/'. $vocabulary->vid, '#required' => $vocabulary->required, '#title' => $vocabulary->name, '#description' => t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'));
       }
       else {
-        $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms);
+        $ntterms = isset($node->taxonomy) ? $terms : array_keys($terms);
+
         $form['taxonomy'][$vocabulary->vid] = taxonomy_form($vocabulary->vid, $ntterms, $help, 'taxonomy');
       }
     }
-- 
GitLab