From cc584e581bcbc2c95ee263c0c9a4b538b3adc155 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Thu, 23 Jan 2014 12:16:58 -0600
Subject: [PATCH] forms: Fix crash if selection-field not set

If a custom list item were added to an email template, and there is no data
for the field (ie. the field is not required) when the template is rendered,
the system would crash.

toString() is required to return a string, no matter what. This patch
cascades the (string) coercion to the current value of the list field if it
is not an instance of a DynamicListItem
---
 include/class.dynamic_forms.php | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php
index c22e563fe..9705d54d4 100644
--- a/include/class.dynamic_forms.php
+++ b/include/class.dynamic_forms.php
@@ -906,7 +906,8 @@ class SelectionField extends FormField {
     }
 
     function toString($item) {
-        return ($item instanceof DynamicListItem) ? $item->toString() : $item;
+        return ($item instanceof DynamicListItem)
+            ? $item->toString() : (string) $item;
     }
 
     function validateEntry($item) {
-- 
GitLab