From e38e8641533533fd436fff06e44c043996a59c38 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Wed, 2 Dec 2015 09:15:38 +0000
Subject: [PATCH] forms: Field Render Mode

Allow fields to internally define the render mode. This allows for fields to
to self render in a view mode when it's not editable.
---
 include/class.forms.php | 6 +++++-
 include/class.list.php  | 1 +
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/class.forms.php b/include/class.forms.php
index 46d55c2d9..69880bebf 100644
--- a/include/class.forms.php
+++ b/include/class.forms.php
@@ -3175,7 +3175,11 @@ class PhoneNumberWidget extends Widget {
 class ChoicesWidget extends Widget {
     function render($options=array()) {
 
-        $mode = isset($options['mode']) ? $options['mode'] : null;
+        $mode = null;
+        if (isset($options['mode']))
+            $mode = $options['mode'];
+        elseif (isset($this->field->options['render_mode']))
+            $mode = $this->field->options['render_mode'];
 
         if ($mode == 'view') {
             if (!($val = (string) $this->field))
diff --git a/include/class.list.php b/include/class.list.php
index ad9b73bce..0c4a7cb19 100644
--- a/include/class.list.php
+++ b/include/class.list.php
@@ -1352,6 +1352,7 @@ implements CustomListItem, TemplateVariable {
             if ($this->isInternal()
                     && ($f=$this->_form->getField('state'))) {
                 $f->ht['required'] = $f->ht['editable'] = false;
+                $f->options['render_mode'] = 'view';
             }
 
         }
-- 
GitLab