Carbon_Fields\Field\Complex_Field::process_loaded_values PHP Method

process_loaded_values() public method

Parse groups of raw field data into the actual field hierarchy.
public process_loaded_values ( array $group_rows )
$group_rows array Group rows
    public function process_loaded_values($group_rows)
    {
        $input_groups = array();
        // Set default values
        $field_names = array();
        foreach ($this->groups as $group) {
            $group_fields = $group->get_fields();
            foreach ($group_fields as $field) {
                $field_names[] = $field->get_name();
                $field->set_value($field->get_default_value());
            }
        }
        if (empty($group_rows)) {
            return;
        }
        // load and parse values and group type
        foreach ($group_rows as $row) {
            if (!preg_match(Helper::get_complex_field_regex($this->name, array_keys($this->groups), $field_names), $row['field_key'], $field_name)) {
                continue;
            }
            $row['field_value'] = maybe_unserialize($row['field_value']);
            $input_groups[$field_name['index']]['type'] = $field_name['group'];
            if (!empty($field_name['trailing'])) {
                $input_groups[$field_name['index']][$field_name['key'] . '_' . $field_name['sub'] . '-' . $field_name['trailing']] = $row['field_value'];
            } else {
                if (!empty($field_name['sub'])) {
                    $input_groups[$field_name['index']][$field_name['key']][$field_name['sub']] = $row['field_value'];
                } else {
                    $input_groups[$field_name['index']][$field_name['key']] = $row['field_value'];
                }
            }
        }
        // create groups list with loaded fields
        ksort($input_groups);
        foreach ($input_groups as $index => $values) {
            $value_group = array('type' => $values['type']);
            $group_fields = $this->groups[$values['type']]->get_fields();
            unset($values['type']);
            foreach ($group_fields as $field) {
                // set value from the group
                $tmp_field = clone $field;
                if (is_a($field, __NAMESPACE__ . '\\Complex_Field')) {
                    $tmp_field->load_values_from_array($values);
                } else {
                    $tmp_field->set_value_from_input($values);
                }
                $value_group[] = $tmp_field;
            }
            $this->values[] = $value_group;
        }
    }