From 4c4f9541e54fcac3488eaf98b70467a1f980b086 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 12 Mar 2021 00:07:50 +0100 Subject: [PATCH] DirectorObjectForm: show inherited non-scalars... ...in select boxes. This should make it more obvious that invalid data has been inherited. refs #2288 --- library/Director/Web/Form/DirectorObjectForm.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index 23bf7eb7..3617f771 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -623,16 +623,16 @@ abstract class DirectorObjectForm extends DirectorForm return; } - $txtInherited = ' ' . $this->translate(' (inherited from "%s")'); + $txtInherited = sprintf($this->translate(' (inherited from "%s")'), $inheritedFrom); if ($el instanceof ZfSelect) { $multi = $el->getMultiOptions(); if (is_bool($inherited)) { $inherited = $inherited ? 'y' : 'n'; } if (is_scalar($inherited) && array_key_exists($inherited, $multi)) { - $multi[null] = $multi[$inherited] . sprintf($txtInherited, $inheritedFrom); + $multi[null] = $multi[$inherited] . $txtInherited; } else { - $multi[null] = $this->translate($this->translate('- inherited -')); + $multi[null] = $this->stringifyInheritedValue($inherited) . $txtInherited; } $el->setMultiOptions($multi); } elseif ($el instanceof ExtensibleSet) { @@ -640,7 +640,7 @@ abstract class DirectorObjectForm extends DirectorForm $el->setAttrib('inheritedFrom', $inheritedFrom); } else { if (is_string($inherited) || is_int($inherited)) { - $el->setAttrib('placeholder', $inherited . sprintf($txtInherited, $inheritedFrom)); + $el->setAttrib('placeholder', $inherited . $txtInherited); } } @@ -648,6 +648,11 @@ abstract class DirectorObjectForm extends DirectorForm $el->setRequired(false); } + protected function stringifyInheritedValue($value) + { + return is_scalar($value) ? $value : substr(json_encode($value), 0, 40); + } + public function setListUrl($url) { $this->listUrl = $url;