Carbon_Fields\Container\Container::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)
    {
        $container_data = array('id' => $this->id, 'type' => $this->type, 'title' => $this->title, 'settings' => $this->settings, 'fields' => array());
        $fields = $this->get_fields();
        foreach ($fields as $field) {
            $field_data = $field->to_json($load);
            $container_data['fields'][] = $field_data;
        }
        return $container_data;
    }

Usage Example

 /**
  * Returns an array that holds the container data, suitable for JSON representation.
  * This data will be available in the Underscore template and the Backbone Model.
  *
  * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
  * @return array
  */
 public function to_json($load)
 {
     $carbon_data = parent::to_json(false);
     // Sends the menu_id to javascript
     $carbon_data = array_merge($carbon_data, array('menu_id' => $this->menu_id));
     return $carbon_data;
 }