From 64bc802e7f74b55504723a2b10084ac9833d344b Mon Sep 17 00:00:00 2001 From: Izhar Aazmi Date: Wed, 11 Nov 2015 16:37:48 +0530 Subject: [PATCH] Fix Jform::bind method JObject handling. Currently it converts all nested objects to array silently (see #3737). Some components relying on old behavior (prior to #3737) may expect object values for the form fields. This fix does not process the entire nested structure, instead converts only binding levels to array for internal iterations. --- libraries/joomla/form/form.php | 62 +++++++++++++--------------------- 1 file changed, 24 insertions(+), 38 deletions(-) diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index 45c0d67ed93db..d80f0c54c28bd 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -126,40 +126,7 @@ public function bind($data) return false; } - // Convert the input to an array. - if (is_object($data)) - { - if ($data instanceof Registry) - { - // Handle a Registry. - $data = $data->toArray(); - } - elseif ($data instanceof JObject) - { - // Handle a JObject. Getting just the properties won't work. We need to convert any nested JObject too. - $data = JArrayHelper::fromObject($data); - } - else - { - // Handle other types of objects. - $data = (array) $data; - } - } - - // Process the input data. - foreach ($data as $k => $v) - { - if ($this->findField($k)) - { - // If the field exists set the value. - $this->data->set($k, $v); - } - elseif (is_object($v) || JArrayHelper::isAssociative($v)) - { - // If the value is an object or an associative array hand it off to the recursive bind level method. - $this->bindLevel($k, $v); - } - } + $this->bindLevel(null, $data); return true; } @@ -177,20 +144,39 @@ public function bind($data) protected function bindLevel($group, $data) { // Ensure the input data is an array. - settype($data, 'array'); + if (is_object($data)) + { + if ($data instanceof Registry) + { + // Handle a Registry. + $data = $data->toArray(); + } + elseif ($data instanceof JObject) + { + // Handle a JObject. + $data = $data->getProperties(); + } + else + { + // Handle other types of objects. + $data = (array) $data; + } + } // Process the input data. foreach ($data as $k => $v) { + $level = $group ? $group . '.' . $k : $k; + if ($this->findField($k, $group)) { // If the field exists set the value. - $this->data->set($group . '.' . $k, $v); + $this->data->set($level, $v); } elseif (is_object($v) || JArrayHelper::isAssociative($v)) { - // If the value is an object or an associative array, hand it off to the recursive bind level method - $this->bindLevel($group . '.' . $k, $v); + // If the value is an object or an associative array, hand it off to the recursive bind level method. + $this->bindLevel($level, $v); } } }