PHP Class Carbon_Fields\Field\Field

Defines the key container methods and their default implementations. Implements factory design pattern.
Show file Open project: htmlburger/carbon-fields Class Usage Examples

Public Properties

Property Type Description
$type string Stores the initial $type variable passed to the factory() method

Protected Properties

Property Type Description
$autoload boolean Whether or not this value should be auto loaded. Applicable to theme options only.
$base_name string The base field name which is used in the container.
$classes array Custom CSS classes.
$conditional_logic array Stores the field conditional logic rules.
$context string The type of the container this field is in
$default_value mixed Default field value
$help_text string Additional text containing information and guidance for the user
$id string Globally unique field identificator. Generated randomly
$label string Field name used as label during field render
$lazyload boolean Whether or not this field will be initialized when the field is in the viewport (visible).
$name string Sanitized field name used as input name attribute during field render
$name_prefix string Prefix to be prepended to the field name during load, save, delete and render
$required boolean Whether or not this field is required.
$store Carbon_Fields\Datastore\Datastore_Interface Field DataStore instance to which save, load and delete calls are delegated
$templates array Stores all the field Backbone templates
$value mixed Field value
$width integer The width of the field.

Public Methods

Method Description
add_class ( string | array $classes ) : object Add custom CSS class to the field html container.
add_template ( $name, $callback ) Adds a new Backbone template
admin_enqueue_scripts ( ) Enqueue admin scripts.
admin_hook_scripts ( ) Hook administration scripts.
admin_hook_styles ( ) Hook administration styles.
admin_init ( ) Instance initialization when in the admin area.
boot ( ) Boot the field once the container is attached.
delete ( ) Delegate delete to the field DataStore instance
factory ( string $type, string $name, string $label = null ) : object Create a new field of type $type and name $name and label $label.
get_autoload ( ) : boolean Return whether or not this value should be auto loaded.
get_base_name ( ) : string Return the field base name.
get_classes ( ) : array Get the field custom CSS classes.
get_conditional_logic ( ) : array Get the conditional logic rules
get_context ( ) : string Return the type of the container this field is in
get_datastore ( ) : object Return the DataStore instance used by the field
get_default_value ( ) : mixed Get default field value
get_help_text ( ) : object Return the field help text
get_html_class ( ) : array Return an array of html classes to be used for the field container
get_id ( ) : string HTML id attribute getter.
get_label ( ) : string Return field label.
get_lazyload ( ) : boolean Return whether or not this field should be lazyloaded.
get_name ( ) : string Return the field name
get_templates ( ) : array Returns all the Backbone templates
get_type ( ) : string Returns the type of the field based on the class.
get_value ( ) : mixed Return the field value
get_width ( ) : integer Get the field width.
help_text ( $help_text ) : object Alias for set_help_text()
init ( ) Perform instance initialization after calling setup()
is_required ( ) : boolean Return whether this field is mandatory for the user
load ( ) Delegate load to the field DataStore instance
make ( $type, $name, $label = null ) An alias of factory().
process_value ( ) : array Allows the value of a field to be processed after loading.
save ( ) Delegate save to the field DataStore instance
set_autoload ( boolean $autoload ) : object Whether or not this value should be auto loaded. Applicable to theme options only.
set_base_name ( $name ) Set field base name as defined in the container.
set_conditional_logic ( $rules ) Set the field visibility conditional logic.
set_context ( $context ) : object Assign the type of the container this field is in
set_datastore ( Carbon_Fields\Datastore\Datastore_Interface $store ) : object Assign DataStore instance for use during load, save and delete
set_default_value ( mixed $default_value ) Set default field value
set_help_text ( $help_text ) : object Set additional text to be displayed during field render, containing information and guidance for the user
set_id ( string $id ) HTML id attribute setter
set_label ( string $label ) Set field label.
set_lazyload ( boolean $lazyload ) : object Whether or not this field will be initialized when the field is in the viewport (visible).
set_name ( string $name ) Set field name.
set_prefix ( string $prefix ) : object Set field name prefix. Calling this method will update the current field name and the conditional logic fields.
set_required ( boolean $required ) : object Whether this field is mandatory for the user
set_value ( mixed $value ) Directly modify the field value
set_value_from_input ( array $input = null ) Load the field value from an input array based on it's name
set_width ( integer $width ) : object Set the field width.
template ( ) Prints the main Underscore template
to_json ( boolean $load ) : array Returns an array that holds the field data, suitable for JSON representation.

Protected Methods

Method Description
__construct ( string $name, string $label ) Create a field from a certain type with the specified label.
clean_type ( $type ) : string Cleans up an object class for usage as HTML class
parse_conditional_rules ( array $rules ) : array Validate and parse the conditional logic rules.

Method Details

__construct() protected method

Create a field from a certain type with the specified label.
protected __construct ( string $name, string $label )
$name string Field name
$label string Field label

add_class() public method

Add custom CSS class to the field html container.
public add_class ( string | array $classes ) : object
$classes string | array
return object $this

add_template() public method

Adds a new Backbone template
public add_template ( $name, $callback )

admin_enqueue_scripts() public static method

Called once per field type.
public static admin_enqueue_scripts ( )

admin_hook_scripts() public static method

Hook administration scripts.
public static admin_hook_scripts ( )

admin_hook_styles() public static method

Hook administration styles.
public static admin_hook_styles ( )

admin_init() public method

Called during field boot.
public admin_init ( )

boot() public method

Boot the field once the container is attached.
public boot ( )

clean_type() protected method

Cleans up an object class for usage as HTML class
protected clean_type ( $type ) : string
return string

delete() public method

Delegate delete to the field DataStore instance
public delete ( )

factory() public static method

Create a new field of type $type and name $name and label $label.
public static factory ( string $type, string $name, string $label = null ) : object
$type string
$name string lower case and underscore-delimited
$label string (optional) Automatically generated from $name if not present
return object $field

get_autoload() public method

Return whether or not this value should be auto loaded.
public get_autoload ( ) : boolean
return boolean

get_base_name() public method

Return the field base name.
public get_base_name ( ) : string
return string

get_classes() public method

Get the field custom CSS classes.
public get_classes ( ) : array
return array

get_conditional_logic() public method

Get the conditional logic rules
public get_conditional_logic ( ) : array
return array

get_context() public method

Return the type of the container this field is in
public get_context ( ) : string
return string

get_datastore() public method

Return the DataStore instance used by the field
public get_datastore ( ) : object
return object $store

get_default_value() public method

Get default field value
public get_default_value ( ) : mixed
return mixed

get_help_text() public method

Return the field help text
public get_help_text ( ) : object
return object $this

get_html_class() public method

Return an array of html classes to be used for the field container
public get_html_class ( ) : array
return array

get_id() public method

HTML id attribute getter.
public get_id ( ) : string
return string

get_label() public method

Return field label.
public get_label ( ) : string
return string

get_lazyload() public method

Return whether or not this field should be lazyloaded.
public get_lazyload ( ) : boolean
return boolean

get_name() public method

Return the field name
public get_name ( ) : string
return string

get_templates() public method

Returns all the Backbone templates
public get_templates ( ) : array
return array

get_type() public method

The class is stripped by the "CarbonFields" prefix. Also the "Field" suffix is removed. Then underscores and backslashes are removed.
public get_type ( ) : string
return string

get_value() public method

Return the field value
public get_value ( ) : mixed
return mixed

get_width() public method

Get the field width.
public get_width ( ) : integer
return integer $width

help_text() public method

Alias for set_help_text()
See also: set_help_text()
public help_text ( $help_text ) : object
return object $this

init() public method

Perform instance initialization after calling setup()
public init ( )

is_required() public method

Return whether this field is mandatory for the user
public is_required ( ) : boolean
return boolean

load() public method

Delegate load to the field DataStore instance
public load ( )

make() public static method

An alias of factory().
See also: Field::factory()
public static make ( $type, $name, $label = null )

parse_conditional_rules() protected method

Validate and parse the conditional logic rules.
protected parse_conditional_rules ( array $rules ) : array
$rules array
return array

process_value() public method

Can be implemented by the extending class if necessary.
public process_value ( ) : array
return array

save() public method

Delegate save to the field DataStore instance
public save ( )

set_autoload() public method

Whether or not this value should be auto loaded. Applicable to theme options only.
public set_autoload ( boolean $autoload ) : object
$autoload boolean
return object $this

set_base_name() public method

Set field base name as defined in the container.
public set_base_name ( $name )

set_conditional_logic() public method

Set the field visibility conditional logic.
public set_conditional_logic ( $rules )

set_context() public method

Assign the type of the container this field is in
public set_context ( $context ) : object
return object $this

set_datastore() public method

Assign DataStore instance for use during load, save and delete
public set_datastore ( Carbon_Fields\Datastore\Datastore_Interface $store ) : object
$store Carbon_Fields\Datastore\Datastore_Interface
return object $this

set_default_value() public method

Set default field value
public set_default_value ( mixed $default_value )
$default_value mixed

set_help_text() public method

Set additional text to be displayed during field render, containing information and guidance for the user
public set_help_text ( $help_text ) : object
return object $this

set_id() public method

HTML id attribute setter
public set_id ( string $id )
$id string

set_label() public method

Set field label.
public set_label ( string $label )
$label string If null, the label will be generated from the field name

set_lazyload() public method

Whether or not this field will be initialized when the field is in the viewport (visible).
public set_lazyload ( boolean $lazyload ) : object
$lazyload boolean
return object $this

set_name() public method

Use only if you are completely aware of what you are doing.
public set_name ( string $name )
$name string Field name, either sanitized or not

set_prefix() public method

Set field name prefix. Calling this method will update the current field name and the conditional logic fields.
public set_prefix ( string $prefix ) : object
$prefix string
return object $this

set_required() public method

Whether this field is mandatory for the user
public set_required ( boolean $required ) : object
$required boolean
return object $this

set_value() public method

Directly modify the field value
public set_value ( mixed $value )
$value mixed

set_value_from_input() public method

Load the field value from an input array based on it's name
public set_value_from_input ( array $input = null )
$input array (optional) Array of field names and values. Defaults to $_POST

set_width() public method

Set the field width.
public set_width ( integer $width ) : object
$width integer
return object $this

template() public method

Prints the main Underscore template
public template ( )

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

Property Details

$autoload protected property

Whether or not this value should be auto loaded. Applicable to theme options only.
See also: set_autoload()
protected bool $autoload
return boolean

$base_name protected property

The base field name which is used in the container.
See also: set_base_name()
protected string $base_name
return string

$classes protected property

Custom CSS classes.
See also: add_class()
protected array $classes
return array

$conditional_logic protected property

Stores the field conditional logic rules.
protected array $conditional_logic
return array

$context protected property

The type of the container this field is in
See also: get_context()
protected string $context
return string

$default_value protected property

Default field value
protected mixed $default_value
return mixed

$help_text protected property

Additional text containing information and guidance for the user
See also: help_text()
protected string $help_text
return string

$id protected property

Globally unique field identificator. Generated randomly
protected string $id
return string

$label protected property

Field name used as label during field render
See also: factory()
See also: set_label()
protected string $label
return string

$lazyload protected property

Whether or not this field will be initialized when the field is in the viewport (visible).
See also: set_lazyload()
protected bool $lazyload
return boolean

$name protected property

Sanitized field name used as input name attribute during field render
See also: factory()
See also: set_name()
protected string $name
return string

$name_prefix protected property

Prefix to be prepended to the field name during load, save, delete and render
protected string $name_prefix
return string

$required protected property

Whether or not this field is required.
See also: set_required()
protected bool $required
return boolean

$store protected property

Field DataStore instance to which save, load and delete calls are delegated
See also: set_datastore()
See also: get_datastore()
protected Datastore_Interface,Carbon_Fields\Datastore $store
return Carbon_Fields\Datastore\Datastore_Interface

$templates protected property

Stores all the field Backbone templates
See also: factory()
See also: add_template()
protected array $templates
return array

$type public property

Stores the initial $type variable passed to the factory() method
See also: factory
public string $type
return string

$value protected property

Field value
protected mixed $value
return mixed

$width protected property

The width of the field.
See also: set_width()
protected int $width
return integer