From 87488e016b15fed9794bc2d0ab72bcc4ba0c367c Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 18 Jul 2014 14:41:36 -0500
Subject: [PATCH] lists: Don't crash rendering a list

This patch fixes an issue where a fatal error would be triggered if the
current value of a selection field on a custom form was a custom list item
that has since been deleted.
---
 include/class.dynamic_forms.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index c0a203646..a8058d7e9 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -1227,8 +1227,8 @@ class SelectionField extends FormField {
             foreach ($this->getList()->getItems() as $i)
                 $this->_choices[$i->get('id')] = $i->get('value');
             if ($this->value && !isset($this->_choices[$this->value])) {
-                $v = DynamicListItem::lookup($this->value);
-                $this->_choices[$v->get('id')] = $v->get('value').' (Disabled)';
+                if ($v = DynamicListItem::lookup($this->value))
+                    $this->_choices[$v->get('id')] = $v->get('value').' (Disabled)';
             }
         }
         return $this->_choices;
-- 
GitLab