Carbon_Fields\Field\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)
    {
        if ($load) {
            $this->load();
        }
        $this->process_value();
        $field_data = array('id' => $this->get_id(), 'type' => $this->get_type(), 'label' => $this->get_label(), 'name' => $this->get_name(), 'base_name' => $this->get_base_name(), 'value' => $this->get_value(), 'default_value' => $this->get_default_value(), 'help_text' => $this->get_help_text(), 'context' => $this->get_context(), 'required' => $this->is_required(), 'lazyload' => $this->get_lazyload(), 'width' => $this->get_width(), 'classes' => $this->get_classes(), 'conditional_logic' => $this->get_conditional_logic());
        return $field_data;
    }

Usage Example

 /**
  * to_json()
  * 
  * You can use this method to modify the field properties that are added to the JSON object.
  * The JSON object is used by the Backbone Model and the Underscore template.
  * 
  * @param bool $load  Should the value be loaded from the database or use the value from the current instance.
  * @return array
  */
 function to_json($load)
 {
     $field_data = parent::to_json($load);
     // do not delete
     $field_data = array_merge($field_data, array('example_property' => $this->example_property));
     return $field_data;
 }
All Usage Examples Of Carbon_Fields\Field\Field::to_json