/**
* Method to bind data to the form for the group level.
*
* @param string $group The dot-separated form group path on which to bind the data.
* @param mixed $data An array or object of data to bind to the form for the group level.
*
* @return void
*
* @since 1.7.0
*/
protected function bindLevel($group, $data)
{
// Ensure the input data is an array.
if (\is_object($data)) {
if ($data instanceof Registry) {
// Handle a Registry.
$data = $data->toArray();
} elseif ($data instanceof CMSObject) {
// Handle a CMSObject.
$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($level, $v);
} elseif (\is_object($v) || ArrayHelper::isAssociative($v)) {
// If the value is an object or an associative array, hand it off to the recursive bind level method.
$this->bindLevel($level, $v);
}
}
}