Gravity_Forms\Gravity_Forms\Settings\Fields\Base
Source: includes/settings/fields/class-base.php:12
Details
-
Kind:
class -
Namespace:
Gravity_Forms\Gravity_Forms\Settings\Fields -
Implements:
ArrayAccess
Properties
| Property | Type | Description |
|---|---|---|
$type | string | Field type. |
$name | string | Field name. |
$label | string | Field label. |
$class | string | Field CSS class. |
$required | bool | Field requirement. |
$fields | Base{} | Nested fields for field. |
$inputs | Base{} | Child inputs for field. |
$default_value | string | array | Default value of field. |
$dependency | array | Dependencies required to display field. |
$save_callback | callable | Function to run when field is saved. |
$validation_callback | callable | Function to run when field is being validated. |
$legacy_validation_callback | callable | Legacy add-on method to call when a field is being validated. |
$settings | Settings | |
$encrypt | bool | Used to check if encryption is suppported. |
$id | int | Field id. |
$callback | callable | Field callback. |
$feedback_callback | callable | Field feedback callback. |
$hidden | string | Field hidden property. |
$html | string | Field html. |
$description | string | Field description. |
$tooltip | string | Field tooltip. |
$after_input | string | Field content after input. |
$choices | array | Field choices. |
$taxonomy | string | Field taxonomy. |
$value | string | Field value. |
$placeholder | string | Field placeholder |
$checkbox | array | Checkbox input attributes |
$select | array | Select input attributes |
$readonly | string | Whether field is readonly |
$error | string | false | Field error message. |
$onchange | string | false | Field onchange attribute. |
$current_render_callback | callable | Current function rendering field. |
Methods
| Method | Description |
|---|---|
__construct() | Initialize field. |
scripts() | Register scripts to enqueue when displaying field. |
styles() | Register styles to enqueue when displaying field. |
prepare_markup() | Render field. |
markup() | Prepare field markup. |
get_attributes() | Returns a set of HTML attributes to be added to the HTML element. |
get_choice_attributes() | Parses the properties of a field choice and returns a set of HTML attributes to be added to the HTML element. |
get_describer() | Get describer element(s) for field. |
get_description() | Renders the description text for a field. |
get_container_classes() | Gets the classes to apply to the field container. |
has_icons() | Determines if any of the available field choices have an icon. |
has_tag() | Determines if any of the available field choices have a tag. |
validate() | Validate posted field value. |
handle_validation() | Validate posted field value. |
is_valid() | Validate posted field value. |
do_validation() | Validate posted field value. |
is_choice_valid() | Determine if the current choice is a match for the submitted field value. |
get_error() | Get error message for field. |
get_error_icon() | Gets the validation error icon. |
set_error() | Set error message for field. |
get_choices() | Helper method to return choices for field. |
get_value() | Helper method to retrieve field value. |
save_field() | Get field value before saving. |
save() | Modify field value before saving. |
get_parsed_name() | Parses the field's name to determine whether it's a simple string or a multi-dimensional array. |
Method Reference
__construct()
public function __construct( $props, $settings )
Initialize field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$props | array | Field properties. | |
$settings | Settings | Settings instance. |
Since: 2.5
Source: includes/settings/fields/class-base.php:308
scripts()
public function scripts()
Register scripts to enqueue when displaying field.
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:334
styles()
public function styles()
Register styles to enqueue when displaying field.
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:347
prepare_markup()
public function prepare_markup()
Render field.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:366
markup()
public function markup()
Prepare field markup.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:399
get_attributes()
public function get_attributes( $default=[] )
Returns a set of HTML attributes to be added to the HTML element.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$default | array | [] | Default set of attributes. |
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:414
get_choice_attributes()
public static function get_choice_attributes( $choice, $field_attributes=[], $default_attributes=[] )
Parses the properties of a field choice and returns a set of HTML attributes to be added to the HTML element.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$choice | array | Field choice meta. | |
$field_attributes | array | [] | Field attributes. |
$default_attributes | array | [] | Default attributes for choice. |
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:505
get_describer()
public function get_describer()
Get describer element(s) for field.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:551
get_description()
public function get_description()
Renders the description text for a field.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:568
get_container_classes()
public function get_container_classes()
Gets the classes to apply to the field container.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:581
has_icons()
public static function has_icons( $choices=[] )
Determines if any of the available field choices have an icon.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$choices | array | [] |
Returns
bool
Since: 2.5
Source: includes/settings/fields/class-base.php:622
has_tag()
public static function has_tag( $choices=[] )
Determines if any of the available field choices have a tag.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$choices | array | [] |
Returns
bool
Since: 2.5.6.4
Source: includes/settings/fields/class-base.php:643
validate()
public function validate( $value )
Validate posted field value.
Run defined callback.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | bool | string | Posted field value. |
Since: 2.5
Deprecated: Deprecated since 2.5-beta-3. Use handle_validation() instead.
Source: includes/settings/fields/class-base.php:671
handle_validation()
public function handle_validation( $value )
Validate posted field value.
Run defined callback.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | bool | string | Posted field value. |
Since: 2.5-beta-3
Source: includes/settings/fields/class-base.php:685
is_valid()
public function is_valid( $value )
Validate posted field value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | bool | string | Posted field value. |
Since: 2.5
Deprecated: Deprecated since 2.5-beta-3 - use do_validation() instead.
Source: includes/settings/fields/class-base.php:712
do_validation()
public function do_validation( $value )
Validate posted field value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | bool | string | Posted field value. |
Since: 2.5-beta-3
Source: includes/settings/fields/class-base.php:726
is_choice_valid()
public static function is_choice_valid( $choice, $value )
Determine if the current choice is a match for the submitted field value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$choice | array | The choice properties. | |
$value | string | array | The submitted field value. |
Returns
bool
Since: 2.5
Source: includes/settings/fields/class-base.php:745
get_error()
public function get_error()
Get error message for field.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:760
get_error_icon()
public function get_error_icon()
Gets the validation error icon.
Returns
string
Since: 2.5
Source: includes/settings/fields/class-base.php:773
set_error()
public function set_error( $error_message='' )
Set error message for field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$error_message | string | '' | Error message. |
Since: 2.5
Source: includes/settings/fields/class-base.php:789
get_choices()
public function get_choices( $choices=false )
Helper method to return choices for field.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$choices | array | callable | bool | false | Existing choices. Defaults to field property. |
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:815
get_value()
public function get_value()
Helper method to retrieve field value.
Returns
array|bool|string
Since: 2.5
Source: includes/settings/fields/class-base.php:845
save_field()
public function save_field( $field_values, $field_value )
Get field value before saving.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field_values | array | Posted field values. | |
$field_value | array | bool | string | Posted value for field. |
Returns
array
Since: 2.5
Source: includes/settings/fields/class-base.php:861
save()
public function save( $value )
Modify field value before saving.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$value | array | bool | string |
Returns
array|bool|string
Since: 2.5
Source: includes/settings/fields/class-base.php:891
get_parsed_name()
public function get_parsed_name()
Parses the field's name to determine whether it's a simple string or a multi-dimensional array.
Examples:
- A string of gravityformsapi will return gravityformsapi.
- A string of gravityformsapi[log_level] will return an array of [ 'gravityformsapi', 'log_level' ].
Returns
string|array
Since: 2.5
Source: includes/settings/fields/class-base.php:982