From 3f1d2c6876d4179ee4c23e2ec1f21fd3d89c8f44 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 18 Mar 2016 20:12:36 +0100 Subject: [PATCH] FormExtensibleSet: fix unsetting choosen values... ...for elements with nested choices --- .../views/helpers/FormExtensibleSet.php | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/application/views/helpers/FormExtensibleSet.php b/application/views/helpers/FormExtensibleSet.php index 77d0da6e..fcf4655c 100644 --- a/application/views/helpers/FormExtensibleSet.php +++ b/application/views/helpers/FormExtensibleSet.php @@ -78,7 +78,7 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement if ($multiOptions !== null) { if (in_array($val, $validOptions)) { - $this->removeOption($multiOptions, $val); + $multiOptions = $this->removeOption($multiOptions, $val); } else { continue; // Value no longer valid } @@ -166,20 +166,25 @@ class Zend_View_Helper_FormExtensibleSet extends Zend_View_Helper_FormElement return $flat; } - private function removeOption(& $options, $option) + private function removeOption($options, $option) { - foreach ($options as $key => $value) { + $unset = array(); + foreach ($options as $key => & $value) { if (is_array($value)) { - if ($this->removeOption($value, $option)) { - return true; + $value = $this->removeOption($value, $option); + if (empty($value)) { + $unset[] = $key; } } elseif ($key === $option) { - unset($options[$key]); - return true; + $unset[] = $key; } } - return false; + foreach ($unset as $key) { + unset($options[$key]); + } + + return $options; } private function suffix($cnt)