Gravity_Forms\Gravity_Forms\Config\GF_Config
Base class for providing advanced functionality when localizing Config Data
for usage in Javascript.
Since: 2.6
Source: includes/config/class-gf-config.php:13
Details
- Kind:
class - Namespace:
Gravity_Forms\Gravity_Forms\Config
Properties
| Property | Type | Description |
|---|---|---|
$parser | GF_Config_Data_Parser | The Data Parser |
$data | array | The data for this config object. |
$name | string | The object name for this config. |
$script_to_localize | string | The ID of the script to localize the data to. |
$priority | int | The priority of this config - can be used to control the order in |
$should_enqueue | bool | Whether the config should enqueue it's data. Can also be handled by overriding the |
$overwrite | bool | Whether this config should overwrite previous values in the object. |
$args | array | An args array. Use in the data() method to retrieve data specific to the specified args. For example, form specific configs will have an array of form ids specified in args. |
Methods
| Method | Description |
|---|---|
__construct() | Constructor |
enable_ajax() | Override this method to add enable ajax loading for a specific config path. |
should_enqueue() | Determine if the config should enqueue its data. If should_enqueue() is a method, |
get_data() | Get the data for the config, passing it through a filter. |
name() | Get the name of the config's object. |
priority() | Get the $priority for the config. |
script_to_localize() | Get the script to localize. |
should_overwrite() | Get whether the config should override previous values. |
set_args() | Sets the $form_ids arrays. |
get_form_ids_arg() | Returns a sanitized array of form ids from the args. |
validate_ajax() | Validates the config data against a hash to ensure it has not been tampered with. |
hash() | Hashes the config data. |
Method Reference
__construct()
public function __construct( GF_Config_Data_Parser $parser )
Constructor
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$parser | GF_Config_Data_Parser |
Source: includes/config/class-gf-config.php:95
enable_ajax()
public function enable_ajax( $config_path, $args )
Override this method to add enable ajax loading for a specific config path.
To enable loading data() via ajax, check if $config_path is one of the paths that are provided by the config. If so, return true.
Example: public function enable_ajax( $config_path, $args ) { return str_starts_with( $config_path, 'gform_theme_config/common/form/product_meta' ); }
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$config_path | string | The full path to the config item when stored in the browser's window object, for example: "gform_theme_config/common/form/product_meta" | |
$args | array | The args used to load the config data. This will be empty for generic config items. For form specific items will be in the format: array( 'form_ids' => array(123,222) ). |
Returns
bool— Return true to load the config data associated with the provided $config_path. Return false otherwise.
Since: 2.9.0
Source: includes/config/class-gf-config.php:124
should_enqueue()
public function should_enqueue()
Determine if the config should enqueue its data. If should_enqueue() is a method,
call it and return the result. If not, simply return the (boolean) value of the property.
Returns
bool
Since: 2.6
Source: includes/config/class-gf-config.php:136
get_data()
public function get_data()
Get the data for the config, passing it through a filter.
Returns
array
Since: 2.6
Source: includes/config/class-gf-config.php:151
name()
public function name()
Get the name of the config's object.
Returns
string
Since: 2.6
Source: includes/config/class-gf-config.php:180
priority()
public function priority()
Get the $priority for the config.
Returns
int
Since: 2.6
Source: includes/config/class-gf-config.php:191
script_to_localize()
public function script_to_localize()
Get the script to localize.
Returns
string
Since: 2.6
Source: includes/config/class-gf-config.php:202
should_overwrite()
public function should_overwrite()
Get whether the config should override previous values.
Returns
bool
Since: 2.6
Source: includes/config/class-gf-config.php:213
set_args()
public function set_args( $args )
Sets the $form_ids arrays.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$args | array | Args array to be set |
Returns
void
Since: 2.9.0
Source: includes/config/class-gf-config.php:226
get_form_ids_arg()
public function get_form_ids_arg()
Returns a sanitized array of form ids from the args.
Returns
array
Since: 2.9.31
Source: includes/config/class-gf-config.php:237
validate_ajax()
public static function validate_ajax()
Validates the config data against a hash to ensure it has not been tampered with.
This method is called via AJAX, initiated by the gform.config.isValid() JS method.
Returns
void
Since: 2.9.0
Source: includes/config/class-gf-config.php:254
hash()
public static function hash( $config )
Hashes the config data.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$config | array |
Returns
string— Returns the hash of the config data.
Since: 2.9.0
Source: includes/config/class-gf-config.php:290