From 9d162755c777249ea73c990804b74a1dfecff2ea Mon Sep 17 00:00:00 2001
From: Dries Buytaert <dries@buytaert.net>
Date: Tue, 21 Feb 2006 08:44:15 +0000
Subject: [PATCH] - Patch #50045 by merlinofchaos: fixed previews getting lost.

---
 modules/poll.module      | 10 ++++------
 modules/poll/poll.module | 10 ++++------
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/modules/poll.module b/modules/poll.module
index 8c6f6be552ef..d2e62de64a7b 100644
--- a/modules/poll.module
+++ b/modules/poll.module
@@ -133,19 +133,17 @@ function poll_form(&$node) {
 
   $form['title'] = array('#type' => 'textfield', '#title' => t('Question'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
 
-  if (!isset($node->choices)) {
-    $node->choices = max(2, count($node->choice) ? count($node->choice) : 5);
-  }
-
-  $form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => $node->choices);
+  $form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5));
   $form['choice']['morechoices'] = array('#type' => 'checkbox', '#title' => t('Need more choices'), '#default_value' => 0, '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."), '#weight' => 1);
   $form['choice'] = form_builder('poll_node_form', $form['choice']);
   if ($form['choice']['morechoices']['#value']) {
     $form['choice']['morechoices']['#value'] = 0;
     $form['choice']['choices']['#value'] *= 2;
-    $node->choices = $form['choice']['choices']['#value'];
   }
 
+  // if the value was changed in a previous iteration, retain it.
+  $node->choices = $form['choice']['choices']['#value'];
+
   // Poll choices
   $form['choice'] += array('#type' => 'fieldset', '#title' => t('Choices'), '#prefix' => '<div class="poll-form">', '#suffix' => '</div>', '#tree' => TRUE);
   for ($a = 0; $a < $node->choices; $a++) {
diff --git a/modules/poll/poll.module b/modules/poll/poll.module
index 8c6f6be552ef..d2e62de64a7b 100644
--- a/modules/poll/poll.module
+++ b/modules/poll/poll.module
@@ -133,19 +133,17 @@ function poll_form(&$node) {
 
   $form['title'] = array('#type' => 'textfield', '#title' => t('Question'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -1);
 
-  if (!isset($node->choices)) {
-    $node->choices = max(2, count($node->choice) ? count($node->choice) : 5);
-  }
-
-  $form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => $node->choices);
+  $form['choice']['choices'] = array('#type' => 'hidden', '#default_value' => max(2, count($node->choice) ? count($node->choice) : 5));
   $form['choice']['morechoices'] = array('#type' => 'checkbox', '#title' => t('Need more choices'), '#default_value' => 0, '#description' => t("If the amount of boxes above isn't enough, check this box and click the Preview button below to add some more."), '#weight' => 1);
   $form['choice'] = form_builder('poll_node_form', $form['choice']);
   if ($form['choice']['morechoices']['#value']) {
     $form['choice']['morechoices']['#value'] = 0;
     $form['choice']['choices']['#value'] *= 2;
-    $node->choices = $form['choice']['choices']['#value'];
   }
 
+  // if the value was changed in a previous iteration, retain it.
+  $node->choices = $form['choice']['choices']['#value'];
+
   // Poll choices
   $form['choice'] += array('#type' => 'fieldset', '#title' => t('Choices'), '#prefix' => '<div class="poll-form">', '#suffix' => '</div>', '#tree' => TRUE);
   for ($a = 0; $a < $node->choices; $a++) {
-- 
GitLab