/** * 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.6 */ protected function bindLevel($group, $data) { // Ensure the input data is an array. settype($data, 'array'); // Process the input data. foreach ($data as $k => $v) { if ($this->findField($k, $group)) { // If the field exists set the value. $this->data->set($group . '.' . $k, $v); } else { if (is_object($v) || GantryArrayHelper::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); } } } }
/** * Method to recursively bind data to a parent object. * * @param object $parent The parent object on which to attach the data values. * @param mixed $data An array or object of data to bind to the parent object. * * @return void * @since 1.6 */ protected function bindData(&$parent, $data) { // Ensure the input data is an array. if (is_object($data)) { $data = get_object_vars($data); } else { $data = (array) $data; } foreach ($data as $k => $v) { if (is_array($v) && GantryArrayHelper::isAssociative($v) || is_object($v)) { $parent->{$k} = new stdClass(); $this->bindData($parent->{$k}, $v); } else { $parent->{$k} = $v; } } }