PHP Class Carbon_Fields\Container\Container

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

Public Properties

Property Type Description
$active_containers array List of containers attached to the current page view
$registered_panel_ids array List of registered unique panel identificators
$settings array List of default container settings
$setup_ready boolean Whether the container was setup
$title string Title of the container

Protected Properties

Property Type Description
$active_fields array List of fields attached to the current page view
$errors array List of error messages to be displayed on the front-end
$fields array List of container fields
$init_containers array List of containers created via factory that should be initialized
$notifications array List of notification messages to be displayed on the front-end
$registered_field_names array List of registered unique field names for this container instance
$store object Container DataStore. Propagated to all container fields
$tabs Tabs available
$templates array Stores all the container Backbone templates

Public Methods

Method Description
__construct ( string $title ) Create a new container
_attach ( ) Called first as part of the container attachment procedure.
_save ( ) Called first as part of the container save procedure.
activate_container ( $container ) Adds a container to the active containers array and triggers an action
activate_field ( $field ) Adds a field to the active fields array and triggers an action
add_fields ( array $fields ) : object Append array of fields to the current fields set. All items of the array must be instances of Field and their names should be unique for all Carbon containers.
add_tab ( string $tab_name, array $fields ) : object Configuration function for adding tab with fields
add_template ( $name, $callback ) Adds a new Backbone template
admin_hook_scripts ( ) Enqueue admin scripts
admin_hook_styles ( ) Enqueue admin styles
attach ( ) Attach the container rendering and helping methods to concrete WordPress Action hooks
boot ( ) Boot the container once it's attached.
check_setup_settings ( array &$settings = [] ) Check if all required container settings have been specified
detach ( ) Revert the result of attach()
drop_unique_field_name ( string $name ) Remove field name $name from the list of unique field names
drop_unique_panel_id ( string $id ) Remove container identificator $id from the list of unique container ids
factory ( string $type, string $name ) : object Create a new container of type $type and name $name and label $label.
get_active_containers ( ) : array Returns all the active containers created via factory
get_active_fields ( ) : array Returns all the active fields created via factory
get_datastore ( ) : object Return the DataStore instance used by container fields
get_fields ( ) : array Returns the private container array of fields.
get_nonce_field ( ) : string Return WordPress nonce field
get_nonce_name ( ) : string Return WordPress nonce name used to identify the current container instance
get_tabs ( ) : array Retrieve all tabs.
get_tabs_json ( ) : array Build the tabs JSON
get_templates ( ) : array Returns all the Backbone templates
get_untabbed_fields ( ) : array Retrieve all fields that are not defined under a specific tab
has_fields ( ) : boolean Perform a check whether the current container has fields
init ( ) Perform instance initialization after calling setup()
init_containers ( ) : object Initialize containers created via factory
is_active ( ) : boolean Perform checks whether the container is active for current request
is_tabbed ( ) : boolean Whether the container is tabbed or not
is_valid_attach ( ) : boolean Perform checks whether the container should be attached during the current request
is_valid_save ( ) : boolean Checks whether the current request is valid
load ( ) Load the value for each field in the container.
make ( $type, $name ) An alias of factory().
save ( $data ) Load submitted data and save each field in the container
set_datastore ( object $store ) : object Assign DataStore instance for use by the container fields
setup ( array $settings = [] ) : object Update container settings and begin initialization
template ( ) Prints the container Underscore template
template_tabs ( ) Underscore template for tabs
to_json ( boolean $load ) : array Returns an array that holds the container data, suitable for JSON representation.
verify_unique_field_name ( string $name ) Perform checks whether there is a field registered with the name $name.
verify_unique_panel_id ( $id ) Perform checks whether there is a container registered with identificator $id

Private Methods

Method Description
create_tab ( string $tab_name, array $fields, integer $queue_end = self::TABS_TAIL ) : object Internal function that creates the tab and associates it with particular field set

Method Details

__construct() public method

Create a new container
public __construct ( string $title )
$title string Unique title of the container

_attach() public method

Responsible for checking it's OK to attach the container and if it is, calling the container-specific attach() method
See also: attach()
See also: is_valid_attach()
public _attach ( )

_save() public method

Responsible for checking the request validity and calling the container-specific save() method
See also: save()
See also: is_valid_save()
public _save ( )

activate_container() public static method

Adds a container to the active containers array and triggers an action
public static activate_container ( $container )

activate_field() public static method

Adds a field to the active fields array and triggers an action
public static activate_field ( $field )

add_fields() public method

If a field does not have DataStore already, the container data store is assigned to them instead.
public add_fields ( array $fields ) : object
$fields array
return object $this

add_tab() public method

Configuration function for adding tab with fields
public add_tab ( string $tab_name, array $fields ) : object
$tab_name string
$fields array
return object $this

add_template() public method

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

admin_hook_scripts() public static method

Enqueue admin scripts
public static admin_hook_scripts ( )

admin_hook_styles() public static method

Enqueue admin styles
public static admin_hook_styles ( )

attach() public method

Attach the container rendering and helping methods to concrete WordPress Action hooks
public attach ( )

boot() public method

Boot the container once it's attached.
public boot ( )

check_setup_settings() public method

Check if all required container settings have been specified
public check_setup_settings ( array &$settings = [] )
$settings array Container settings

detach() public method

Revert the result of attach()
public detach ( )

drop_unique_field_name() public method

Remove field name $name from the list of unique field names
public drop_unique_field_name ( string $name )
$name string

drop_unique_panel_id() public static method

Remove container identificator $id from the list of unique container ids
public static drop_unique_panel_id ( string $id )
$id string

factory() public static method

Create a new container of type $type and name $name and label $label.
public static factory ( string $type, string $name ) : object
$type string
$name string Human-readable name of the container
return object $container

get_active_containers() public static method

Returns all the active containers created via factory
public static get_active_containers ( ) : array
return array

get_active_fields() public static method

Returns all the active fields created via factory
public static get_active_fields ( ) : array
return array

get_datastore() public method

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

get_fields() public method

Use only if you are completely aware of what you are doing.
public get_fields ( ) : array
return array

get_nonce_field() public method

Return WordPress nonce field
public get_nonce_field ( ) : string
return string

get_nonce_name() public method

Return WordPress nonce name used to identify the current container instance
public get_nonce_name ( ) : string
return string

get_tabs() public method

Create a default tab if there are any untabbed fields.
public get_tabs ( ) : array
return array

get_tabs_json() public method

Build the tabs JSON
public get_tabs_json ( ) : array
return array

get_templates() public method

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

get_untabbed_fields() public method

Retrieve all fields that are not defined under a specific tab
public get_untabbed_fields ( ) : array
return array

has_fields() public method

Perform a check whether the current container has fields
public has_fields ( ) : boolean
return boolean

init() abstract public method

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

init_containers() public static method

Initialize containers created via factory
public static init_containers ( ) : object
return object

is_active() public method

Perform checks whether the container is active for current request
public is_active ( ) : boolean
return boolean True if the container is active

is_tabbed() public method

Whether the container is tabbed or not
public is_tabbed ( ) : boolean
return boolean

is_valid_attach() public method

Perform checks whether the container should be attached during the current request
public is_valid_attach ( ) : boolean
return boolean True if the container is allowed to be attached

is_valid_save() public method

Checks whether the current request is valid
public is_valid_save ( ) : boolean
return boolean

load() public method

Could be used internally during container rendering
public load ( )

make() public static method

An alias of factory().
See also: Container::factory()
public static make ( $type, $name )

save() public method

Load submitted data and save each field in the container
See also: is_valid_save()
public save ( $data )

set_datastore() public method

Assign DataStore instance for use by the container fields
public set_datastore ( object $store ) : object
$store object
return object $this

setup() public method

Update container settings and begin initialization
See also: init()
public setup ( array $settings = [] ) : object
$settings array
return object $this

template() public method

Prints the container Underscore template
public template ( )

template_tabs() public method

Underscore template for tabs
public template_tabs ( )

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

verify_unique_field_name() public method

If not, the field name is recorded.
public verify_unique_field_name ( string $name )
$name string

verify_unique_panel_id() public static method

Perform checks whether there is a container registered with identificator $id
public static verify_unique_panel_id ( $id )

Property Details

$active_containers public static property

List of containers attached to the current page view
See also: _attach()
public static array $active_containers
return array

$active_fields protected static property

List of fields attached to the current page view
See also: _attach()
protected static array $active_fields
return array

$errors protected property

List of error messages to be displayed on the front-end
protected array $errors
return array

$fields protected property

List of container fields
See also: add_fields()
protected array $fields
return array

$init_containers protected static property

List of containers created via factory that should be initialized
protected static array $init_containers
return array

$notifications protected property

List of notification messages to be displayed on the front-end
protected array $notifications
return array

$registered_field_names protected property

List of registered unique field names for this container instance
See also: verify_unique_field_name()
protected array $registered_field_names
return array

$registered_panel_ids public static property

List of registered unique panel identificators
See also: verify_unique_panel_id()
public static array $registered_panel_ids
return array

$settings public property

List of default container settings
See also: init()
public array $settings
return array

$setup_ready public property

Whether the container was setup
public bool $setup_ready
return boolean

$store protected property

Container DataStore. Propagated to all container fields
See also: set_datastore()
See also: get_datastore()
protected object $store
return object

$tabs protected property

Tabs available
protected $tabs

$templates protected property

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

$title public property

Title of the container
public string $title
return string