From 137011df918d911c9811b8d503ca5af037284c4c Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Fri, 30 Jul 2010 03:06:18 +0000
Subject: [PATCH] - Patch #844388 by lotyrin, bjaspan, effulgentsia: taxonomy
 terms disappear from node preview if previewed more than once.

---
 modules/field/field.attach.inc | 23 +++++++++++++++++------
 modules/node/node.pages.inc    |  7 +++----
 modules/taxonomy/taxonomy.test |  6 ++++++
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 3383a5793b37..faa8743c2b65 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -1035,10 +1035,17 @@ function field_attach_delete_revision($entity_type, $entity) {
 /**
  * Prepare field data prior to display.
  *
- * This function must be called before field_attach_view(). It lets field
- * types and formatters load additional data needed for display, and
- * therefore accepts an array of entities to allow query optimisation when
- * displaying lists of entities.
+ * This function lets field types and formatters load additional data
+ * needed for display that is not automatically loaded during
+ * field_attach_load(). It accepts an array of entities to allow query
+ * optimisation when displaying lists of entities.
+ *
+ * field_attach_prepare_view() and field_attach_view() are two halves
+ * of the same operation. It is safe to call
+ * field_attach_prepare_view() multiple times on the same entity
+ * before calling field_attach_view() on it, but calling any Field
+ * API operation on an entity between passing that entity to these two
+ * functions may yield incorrect results.
  *
  * @param $entity_type
  *   The type of $entities; e.g. 'node' or 'user'.
@@ -1076,8 +1083,12 @@ function field_attach_prepare_view($entity_type, $entities, $view_mode) {
  * Each field is displayed according to the display options specified in the
  * $instance definition for the given $view_mode.
  *
- * The entity must have run through field_attach_prepare_view() beforehands.
- * @see field_attach_prepare_view()
+ * field_attach_prepare_view() and field_attach_view() are two halves
+ * of the same operation. It is safe to call
+ * field_attach_prepare_view() multiple times on the same entity
+ * before calling field_attach_view() on it, but calling any Field
+ * API operation on an entity between passing that entity to these two
+ * functions may yield incorrect results.
  *
  * Sample structure:
  * @code
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index 96a4ebfcb21b..d360bad3a03f 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -339,11 +339,10 @@ function node_preview($node) {
     field_attach_prepare_view('node', $nodes, 'full');
 
     // Display a preview of the node.
-    // Previewing alters $node so it needs to be cloned.
     if (!form_get_errors()) {
-      $cloned_node = clone $node;
-      $cloned_node->in_preview = TRUE;
-      $output = theme('node_preview', array('node' => $cloned_node));
+      $node->in_preview = TRUE;
+      $output = theme('node_preview', array('node' => $node));
+      unset($node->in_preview);
     }
     drupal_set_title(t('Preview'), PASS_THROUGH);
 
diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test
index 605b6a86e2f5..391dc01df528 100644
--- a/modules/taxonomy/taxonomy.test
+++ b/modules/taxonomy/taxonomy.test
@@ -451,6 +451,12 @@ class TaxonomyTermTestCase extends TaxonomyWebTestCase {
 
     $this->drupalGet('node/' . $node->nid);
     $this->assertText($term2->name, t('Term is displayed when viewing the node.'));
+
+    //Preview the node
+    $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Preview'));
+    $this->assertNoUniqueText($term2->name, t('Term is displayed when previewing the node.'));
+    $this->drupalPost(NULL, NULL, t('Preview'));
+    $this->assertNoUniqueText($term2->name, t('Term is displayed when previewing the node again.'));
   }
 
   /**
-- 
GitLab