public function onDispatchCustomFieldRule( mixed $field, mixed $value, array &$data ) : bool

Fires before dispatching a custom field rule.


Description

Trigger hook to allow external plugins to dispatch a custom rule during the saving process.

This process is mainly used to collect the details specified by the customers into different database tables.

In case the rule needs to validate the entered data, it is possible to throw an exception to abort the saving process.

It is possible to access the rule of the field with $field->get('rule').


Parameters

$field

(Field)  The custom field instance. This class is part of the E4J\VikRestaurants\CustomFields namespace.

$value

(mixed)  The value of the field set in request.

&$data

(array)  The array data to fill-in in case of specific rules (name, e-mail, etc...).

Return Value

Boolean. True to avoid dispatching the default system rules.


Example

The example registers the specified country code into the customer database table.

/**
 * Trigger hook to allow external plugins to dispatch a custom rule.
 *
 * @param   Field  $field  The custom field instance.
 * @param   mixed  $value  The value of the field set in request.
 * @param   array  &$data  The array data to fill-in in case of
 *                          specific rules (name, e-mail, etc...).
 *
 * @return  bool   True to avoid dispatching the default system rules.
 */
public function onDispatchCustomFieldRule($field, $value, &$data)
{
    // make sure we are dispatching a field with "country" rule
    if ($field->get('rule') !== 'country') {
        // different rule
        return false;
    }

    // register country code within the array data to be saved into the customer record
    $data['country_code'] = $value;

    return true;
}

Changelog

Version Description
1.9 Introduced.
Last Update: 2023-12-29 14:15
Helpful?