From 9c75ef60db1d014addec07ad1074de795ebc4bdf Mon Sep 17 00:00:00 2001 From: Jared Hancock <jared@osticket.com> Date: Mon, 1 Sep 2014 22:25:00 -0500 Subject: [PATCH] forms: Any field can have sub fields Not just the SelectionField. This will make room for the InlineFormField --- include/class.dynamic_forms.php | 19 +++++++++++++------ include/class.forms.php | 12 ++++++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 4fd745e8c..1add7ca24 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -249,8 +249,8 @@ Filter::addSupportedMatches(/* @trans */ 'User Data', function() { if (!$f->hasData()) continue; $matches['field.'.$f->get('id')] = __('User').' / '.$f->getLabel(); - if (($fi = $f->getImpl()) instanceof SelectionField) { - foreach ($fi->getList()->getForm()->getFields() as $p) { + if (($fi = $f->getImpl()) && $fi->hasSubFields()) { + foreach ($fi->getSubFields() as $p) { $matches['field.'.$f->get('id').'.'.$p->get('id')] = __('User').' / '.$f->getLabel().' / '.$p->getLabel(); } @@ -339,8 +339,8 @@ Filter::addSupportedMatches(/* @trans */ 'Ticket Data', function() { if (!$f->hasData()) continue; $matches['field.'.$f->get('id')] = __('Ticket').' / '.$f->getLabel(); - if (($fi = $f->getImpl()) instanceof SelectionField) { - foreach ($fi->getList()->getForm()->getFields() as $p) { + if (($fi = $f->getImpl()) && $fi->hasSubFields()) { + foreach ($fi->getSubFields() as $p) { $matches['field.'.$f->get('id').'.'.$p->get('id')] = __('Ticket').' / '.$f->getLabel().' / '.$p->getLabel(); } @@ -381,8 +381,8 @@ Filter::addSupportedMatches(/* trans */ 'Custom Forms', function() { if (!$f->hasData()) continue; $matches['field.'.$f->get('id')] = $form->getTitle().' / '.$f->getLabel(); - if (($fi = $f->getImpl()) instanceof SelectionField) { - foreach ($fi->getList()->getProperties() as $p) { + if (($fi = $f->getImpl()) && $fi->hasSubFields()) { + foreach ($fi->getSubFields() as $p) { $matches['field.'.$f->get('id').'.'.$p->get('id')] = $form->getTitle().' / '.$f->getLabel().' / '.$p->getLabel(); } @@ -1030,6 +1030,13 @@ class SelectionField extends FormField { return true; } + function hasSubFields() { + return true; + } + function getSubFields() { + return $this->getConfigurationForm()->getFields(); + } + function toString($items) { return ($items && is_array($items)) ? implode(', ', $items) : (string) $items; diff --git a/include/class.forms.php b/include/class.forms.php index d8c93f2c7..3b55aa353 100644 --- a/include/class.forms.php +++ b/include/class.forms.php @@ -538,6 +538,18 @@ class FormField { return false; } + /** + * Indicates if the field has subfields accessible via getSubFields() + * method. Useful for filter integration. Should connect with + * getFilterData() + */ + function hasSubFields() { + return false; + } + function getSubFields() { + return null; + } + function getConfigurationForm($source=null) { if (!$this->_cform) { $type = static::getFieldType($this->get('type')); -- GitLab