Carbon_Fields\Field\Complex_Field::to_json PHP Method

to_json() public method

This data will be available in the Underscore template and the Backbone Model.
public to_json ( boolean $load ) : array
$load boolean Should the value be loaded from the database or use the value from the current instance.
return array
    public function to_json($load)
    {
        $complex_data = parent::to_json($load);
        $groups_data = array();
        $values_data = array();
        foreach ($this->groups as $group) {
            $groups_data[] = $group->to_json(false);
        }
        foreach ($this->values as $fields) {
            $group = $this->get_group_by_name($fields['type']);
            unset($fields['type']);
            $data = array('name' => $group->get_name(), 'label' => $group->get_label(), 'group_id' => $group->get_group_id(), 'fields' => array());
            foreach ($fields as $index => $field) {
                $data['fields'][] = $field->to_json(false);
            }
            $values_data[] = $data;
        }
        $complex_data = array_merge($complex_data, array('layout' => $this->layout, 'labels' => $this->labels, 'min' => $this->get_min(), 'max' => $this->get_max(), 'multiple_groups' => count($groups_data) > 1, 'groups' => $groups_data, 'value' => $values_data));
        return $complex_data;
    }