From df5ff0b0003429c633b32bed22e70c2982f1313c Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 16 Mar 2015 10:36:06 -0500
Subject: [PATCH] oops: Fix dropped custom data from API requests

For a yet unknown reason, the association between the field implementations
and the DynamicFormEntry object is not maintained from calls to
DynamicFormEntry::getFields().

This patch addresses the issue by always associating the "form" when
returning from ::getFields()
---
 include/class.dynamic_forms.php | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index c97739963..2fdb0088a 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -735,7 +735,6 @@ class DynamicFormEntry extends VerySimpleModel {
             // Get all dynamic fields associated with the form
             //  even when stored elsewhere -- important during validation
             foreach ($this->getForm()->getDynamicFields() as $field) {
-                $field->setForm($this);
                 $field = $field->getImpl($field);
                 if ($field instanceof ThreadEntryField)
                     continue;
@@ -744,13 +743,11 @@ class DynamicFormEntry extends VerySimpleModel {
             // Get answers to entries
             foreach ($this->getAnswers() as $a) {
                 if (!($f = $a->getField())) continue;
-                // Perhaps an answer of deleted field
-                if (!isset($this->_fields[$f->get('id')])) {
-                    $f->setForm($this);
-                }
                 $this->_fields[$f->get('id')] = $f;
             }
         }
+        foreach ($this->_fields as $F)
+            $F->setForm($this);
 
         return $this->_fields;
     }
-- 
GitLab