Skip to content

Commit

Permalink
Merge pull request #8379 from izharaazmi/jform-bind
Browse files Browse the repository at this point in the history
Fix Jform::bind method JObject handling
  • Loading branch information
rdeutz committed Nov 21, 2015
2 parents ef6c1b1 + 64bc802 commit dc13ef5
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions libraries/joomla/form/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit dc13ef5

Please sign in to comment.