PHP Класс Habari\FormControl

Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$caption string
$container FormContainer The container that contains this control
$controls_js True if the controls.init script has been output, false if not
$errors array An array of errors that is filled when the control is passed for validation
$has_errors boolean True when this control has errors, can be true with $errors isn't when the errors propagate to the container
$helptext boolean | string This is help text for the control, if it is set
$initial_value mixed This is the intially assigned value of the control, set and used internally
$name string The name of the control for the purposes of manipulating it from the container object
$on_enable array An array of enable handlers for this control
$on_save array An array of save handlers for this control
$on_success array An array of success handlers for this control
$properties array Contains an array of properties used to assign to the output HTML
$settings array Contains an array of settings that control the behavior of this control
$storage habari\FormStorage | null The storage object for this form
$validators array An array of validators to execute on this control
$value mixed This is the value of the control, which will differ depending on at what time you access it
$value_set_manually boolean If the value of this control was set manually, this should be true
$vars array These vars are added internally to the theme for output by the template

Открытые методы

Метод Описание
__construct ( string $name, habari\FormStorage | string | null $storage = 'null:null', array $properties = [], array $settings = [] ) Construct a control.
_extend ( ) This function is called after __construct(). It does nothing, but its descendants might do something.
add_class ( array | string $classes ) : FormControl Add one or more CSS classes to this control
add_input_array ( integer | string $value ) : FormControl Add a value to the input_array setting
add_template_class ( string $target, array | string $classes ) : FormControl Add one or more CSS classes to this control's template
add_validator ( mixed $validator, mixed $option = null ) : FormControl Add a validation function to this control Multiple parameters are passed as parameters to the validation function
clear ( ) Set this control to its initial value
control_id ( ) : string Obtain a unique identifier for this control that is the same every time the form is generated
control_type ( ) : string Get the type of control this is (without the "FormControl" and in lower case) Usually used for template selection
controls_js ( string $out ) : string Render the controls.init script prior to the supplied script only if it hasn't already been rendered
create ( string $name, habari\FormStorage | string | null $storage = 'null:null', array $properties = [], array $settings = [] ) : mixed | FormControl Create a new instance of this class and return it, use the fluent interface
do_success ( FormUI $form ) : boolean | string Calls the success callback for the form, and saves the form value to the control's storage location
error_wrap ( string $output, array $errors ) : string Wrap the output of a control (or some text content) with error content
from_args ( array $arglist ) : FormControl Take an array of parameters, use the first as the FormControl class/type, and run the constructor with the rest
get ( Theme $theme ) : string Produce the control for display
get_form ( ) : FormUI Find the form that holds this control
get_id ( boolean $force_set = true ) : string | null Produce a unique id (not name) for this control for use with labels and such, only if one is not provided in the control properties
get_id_component ( ) : boolean | string Get a string that will be used to generate a component of a control's HTML id
get_label ( ) : string Get a text label for this control
get_setting ( string $name, mixed $default = null ) : mixed Get the value of a setting
get_template ( ) : array Get a list of potential templates that can render this control
get_theme ( ) : Theme Retreive the Theme used to display this form component and its descendants
get_visualizer ( ) Returns the HTML id of the element that the control exposes as a target, for example, for labels
input_name ( ) : string Get the name to use for the input field
is_enabled ( ) : boolean Determine if this controls should be enabled
label ( string $label ) : FormControlLabel Shortcut to wrap this control in a label
load ( ) Load this control's initial data from the initialized storage location
on_save ( mixed $callback ) : FormControl Set a function to call on form submission success
on_success ( mixed $callback ) : FormControl Set a function to call on form submission success
pop_input_array ( ) : FormControl Remove the most recent input_array setting
pre_out ( ) : string Output this once when the control is first output to the page
prep_theme ( Theme $theme_obj ) : Theme
process ( ) Obtain the value of this control as supplied by the incoming $_POST values
remove_class ( array | string $classes ) : FormControl Remove one or more CSS classes from this control
remove_validator ( string $name ) Removes a validation function from this control
save ( ) Save this control's data to the initialized storage location
set_container ( FormContainer $container ) Set the container for this control
set_enable ( Callable $enabler ) : FormControl Set a function to use to determine if this control should be enabled or provided in the form
set_helptext ( string $helptext ) : FormControl
set_properties ( array $properties, boolean $override = false ) : FormControl Set the HTML-related properties of this control
set_property ( string $name, mixed $value ) : FormControl Set an HTML-related property of this control
set_setting ( string $name, mixed $value ) : FormControl Set the value of a single setting
set_settings ( array $settings, boolean $override = false ) : FormControl
set_storage ( habari\FormStorage | string | null $storage ) : FormControl Set the storage for this control
set_template ( string | array $template ) : FormControl Set a template for use with this control
set_template_html ( Callable | string $template ) : FormControl Set an HTML value directly for the output of a control
set_template_properties ( string $target, array $properties, boolean $override = false ) : FormControl Set the HTML-related properties of this control's template
set_value ( mixed $value, boolean $manually = true ) : FormControl Set the value of the control
validate ( ) : array Runs any attached validation functions to check validation of this control.
wrap_by ( Callable | string $wrapper, mixed $thing ) : string Process a thing either using an sprintf-style string, or a closure

Описание методов

__construct() публичный Метод

Construct a control.
public __construct ( string $name, habari\FormStorage | string | null $storage = 'null:null', array $properties = [], array $settings = [] )
$name string The name of the control
$storage habari\FormStorage | string | null A storage location for the data collected by the control
$properties array An array of properties that apply to the output HTML
$settings array An array of settings that apply to this control object

_extend() публичный Метод

This function is called after __construct(). It does nothing, but its descendants might do something.
public _extend ( )

add_class() публичный Метод

Add one or more CSS classes to this control
public add_class ( array | string $classes ) : FormControl
$classes array | string An array or a string of classes to add to this control
Результат FormControl $this

add_input_array() публичный Метод

Add a value to the input_array setting
public add_input_array ( integer | string $value ) : FormControl
$value integer | string The value to use as the array part of the input name
Результат FormControl $this Fluent interface

add_template_class() публичный Метод

Add one or more CSS classes to this control's template
public add_template_class ( string $target, array | string $classes ) : FormControl
$target string The name of the targeted element in the control template
$classes array | string An array or a string of classes to add to this control's template
Результат FormControl $this

add_validator() публичный Метод

Add a validation function to this control Multiple parameters are passed as parameters to the validation function
public add_validator ( mixed $validator, mixed $option = null ) : FormControl
$validator mixed A callback function
$option mixed Multiple parameters added to those used to call the validator callback
Результат FormControl Returns the control for chained execution

clear() публичный Метод

Set this control to its initial value
public clear ( )

control_id() публичный Метод

Obtain a unique identifier for this control that is the same every time the form is generated
public control_id ( ) : string
Результат string

control_type() публичный Метод

Get the type of control this is (without the "FormControl" and in lower case) Usually used for template selection
public control_type ( ) : string
Результат string The type of the control in lower case

controls_js() публичный Метод

Render the controls.init script prior to the supplied script only if it hasn't already been rendered
public controls_js ( string $out ) : string
$out string An existing script that depends on controls.init
Результат string The script with the controls.init script prepended, if needed

create() публичный статический Метод

Create a new instance of this class and return it, use the fluent interface
public static create ( string $name, habari\FormStorage | string | null $storage = 'null:null', array $properties = [], array $settings = [] ) : mixed | FormControl
$name string The name of the control
$storage habari\FormStorage | string | null A storage location for the data collected by the control
$properties array An array of properties that apply to the output HTML
$settings array An array of settings that apply to this control object
Результат mixed | FormControl An instance of the referenced FormControl with the supplied parameters

do_success() публичный Метод

Calls the success callback for the form, and saves the form value to the control's storage location
public do_success ( FormUI $form ) : boolean | string
$form FormUI The form this control belongs to
Результат boolean | string A string to replace the rendering of the form with, or false

error_wrap() публичный Метод

Wrap the output of a control (or some text content) with error content
public error_wrap ( string $output, array $errors ) : string
$output string The HTML to wrap
$errors array An array of error strings
Результат string The returned output

from_args() публичный статический Метод

Take an array of parameters, use the first as the FormControl class/type, and run the constructor with the rest
public static from_args ( array $arglist ) : FormControl
$arglist array The array of arguments
Результат FormControl The created control.

get() публичный Метод

Produce the control for display
public get ( Theme $theme ) : string
$theme Theme The theme that will be used to render the template
Результат string The output of the template

get_form() публичный Метод

Find the form that holds this control
public get_form ( ) : FormUI
Результат FormUI The form that this control is in

get_id() публичный Метод

Produce a unique id (not name) for this control for use with labels and such, only if one is not provided in the control properties
public get_id ( boolean $force_set = true ) : string | null
$force_set boolean Default to true, forcing the id to be set to the name of the control if it's not set already
Результат string | null The id of this control, or null if it's not set and not forced

get_id_component() публичный Метод

Get a string that will be used to generate a component of a control's HTML id
public get_id_component ( ) : boolean | string
Результат boolean | string False if this component doesn't contribute to id creation, or the string component

get_label() публичный Метод

Get a text label for this control
public get_label ( ) : string
Результат string The label

get_setting() публичный Метод

Get the value of a setting
public get_setting ( string $name, mixed $default = null ) : mixed
$name string The name of the setting to get
$default mixed The default value to use if the setting is not set
Результат mixed The value fo the setting or the default supplied

get_template() публичный Метод

Get a list of potential templates that can render this control
public get_template ( ) : array
Результат array An array of template names in fallback order

get_theme() публичный Метод

Retreive the Theme used to display this form component and its descendants
public get_theme ( ) : Theme
Результат Theme The theme object to display the template for the control

get_visualizer() публичный Метод

Returns the HTML id of the element that the control exposes as a target, for example, for labels
public get_visualizer ( )

input_name() публичный Метод

Get the name to use for the input field
public input_name ( ) : string
Результат string The name to use in the HTML for this control

is_enabled() публичный Метод

Determine if this controls should be enabled
public is_enabled ( ) : boolean
Результат boolean True if enabled, false if not enabled

label() публичный Метод

Shortcut to wrap this control in a label
public label ( string $label ) : FormControlLabel
$label string The caption of the label
Результат FormControlLabel The label control is returned. FYI, THIS BREAKS THE FLUENT INTERFACE.

load() публичный Метод

Load this control's initial data from the initialized storage location
public load ( )

on_save() публичный Метод

Set a function to call on form submission success
public on_save ( mixed $callback ) : FormControl
$callback mixed A callback function or a plugin filter name.
Результат FormControl $this Fluent interface

on_success() публичный Метод

Set a function to call on form submission success
public on_success ( mixed $callback ) : FormControl
$callback mixed A callback function or a plugin filter name (FormUI $form)
Результат FormControl $this Fluent interface

pop_input_array() публичный Метод

Remove the most recent input_array setting
public pop_input_array ( ) : FormControl
Результат FormControl $this Fluent interface

pre_out() публичный Метод

Output this once when the control is first output to the page
public pre_out ( ) : string
Результат string

prep_theme() публичный Метод

public prep_theme ( Theme $theme_obj ) : Theme
$theme_obj Theme
Результат Theme

process() публичный Метод

Obtain the value of this control as supplied by the incoming $_POST values
public process ( )

remove_class() публичный Метод

Remove one or more CSS classes from this control
public remove_class ( array | string $classes ) : FormControl
$classes array | string An array or a string of classes to remove from this control
Результат FormControl $this

remove_validator() публичный Метод

Removes a validation function from this control
public remove_validator ( string $name )
$name string The name of the validator to remove

save() публичный Метод

Save this control's data to the initialized storage location
public save ( )

set_container() публичный Метод

Set the container for this control
public set_container ( FormContainer $container )
$container FormContainer A container that this control is inside

set_enable() публичный Метод

Set a function to use to determine if this control should be enabled or provided in the form
public set_enable ( Callable $enabler ) : FormControl
$enabler Callable A function to call to determine if this control should be enabled
Результат FormControl $this

set_helptext() публичный Метод

public set_helptext ( string $helptext ) : FormControl
$helptext string Help text to appear for the control
Результат FormControl $this

set_properties() публичный Метод

Set the HTML-related properties of this control
public set_properties ( array $properties, boolean $override = false ) : FormControl
$properties array An array of properties that will be associated to this control's HTML output
$override boolean If true, the supplied properties completely replace the existing ones
Результат FormControl $this

set_property() публичный Метод

Set an HTML-related property of this control
public set_property ( string $name, mixed $value ) : FormControl
$name string The name of the property to set
$value mixed The value to set the property to
Результат FormControl $this

set_setting() публичный Метод

Set the value of a single setting
public set_setting ( string $name, mixed $value ) : FormControl
$name string The name of the setting
$value mixed The value of the setting
Результат FormControl $this Fluent interface

set_settings() публичный Метод

public set_settings ( array $settings, boolean $override = false ) : FormControl
$settings array An array of settings that affect the behavior of this control object
$override boolean If true, use the provided array to override the existing one
Результат FormControl $this

set_storage() публичный Метод

Set the storage for this control
public set_storage ( habari\FormStorage | string | null $storage ) : FormControl
$storage habari\FormStorage | string | null A storage location for the data collected by the control
Результат FormControl $this

set_template() публичный Метод

Set a template for use with this control
public set_template ( string | array $template ) : FormControl
$template string | array A template fallback list to search for this template
Результат FormControl $this

set_template_html() публичный Метод

Set an HTML value directly for the output of a control
public set_template_html ( Callable | string $template ) : FormControl
$template Callable | string The template to use for output of this control
Результат FormControl $this

set_template_properties() публичный Метод

Set the HTML-related properties of this control's template
public set_template_properties ( string $target, array $properties, boolean $override = false ) : FormControl
$target string the target element in the template to apply the properties to
$properties array An array of properties that will be associated to this control template's HTML output
$override boolean If true, the supplied properties completely replace the existing ones
Результат FormControl $this

set_value() публичный Метод

Set the value of the control
public set_value ( mixed $value, boolean $manually = true ) : FormControl
$value mixed The initial value of the control
$manually boolean True if the value was set manually in code rather than being submitted
Результат FormControl $this

validate() публичный Метод

Runs any attached validation functions to check validation of this control.
public validate ( ) : array
Результат array An array of string validation error descriptions or an empty array if no errors were found.

wrap_by() публичный Метод

Process a thing either using an sprintf-style string, or a closure
public wrap_by ( Callable | string $wrapper, mixed $thing ) : string
$wrapper Callable | string An sprintf-style wrapper or a function that accepts the same arguments as the call to this
$thing mixed One or more things to use as parameters to the sprintf/closure
Результат string The resultant string produced by applying the closure or sprintf template

Описание свойств

$caption публичное свойство

public string $caption
Результат string

$container публичное свойство

The container that contains this control
public FormContainer,habari $container
Результат FormContainer

$controls_js статическое публичное свойство

True if the controls.init script has been output, false if not
static public $controls_js

$errors публичное свойство

An array of errors that is filled when the control is passed for validation
public array $errors
Результат array

$has_errors публичное свойство

True when this control has errors, can be true with $errors isn't when the errors propagate to the container
public bool $has_errors
Результат boolean

$helptext публичное свойство

This is help text for the control, if it is set
public bool|string $helptext
Результат boolean | string

$initial_value публичное свойство

This is the intially assigned value of the control, set and used internally
public mixed $initial_value
Результат mixed

$name публичное свойство

The name of the control for the purposes of manipulating it from the container object
public string $name
Результат string

$on_enable публичное свойство

An array of enable handlers for this control
public array $on_enable
Результат array

$on_save публичное свойство

An array of save handlers for this control
public array $on_save
Результат array

$on_success публичное свойство

An array of success handlers for this control
public array $on_success
Результат array

$properties публичное свойство

Contains an array of properties used to assign to the output HTML
public array $properties
Результат array

$settings публичное свойство

Contains an array of settings that control the behavior of this control
public array $settings
Результат array

$storage публичное свойство

The storage object for this form
public FormStorage,habari|null $storage
Результат habari\FormStorage | null

$validators публичное свойство

An array of validators to execute on this control
public array $validators
Результат array

$value публичное свойство

This is the value of the control, which will differ depending on at what time you access it
public mixed $value
Результат mixed

$value_set_manually публичное свойство

If the value of this control was set manually, this should be true
public bool $value_set_manually
Результат boolean

$vars публичное свойство

These vars are added internally to the theme for output by the template
public array $vars
Результат array