Closed kenneth-bolivar-castro closed 8 years ago
Added "parseAsFirstValueOrCallback" protected method, where a custom function can be call it based on metadata defined into YML definition.
The "getFieldValue()" method changed, it check first a token implementation, then it tries to retrieve value from first value into field if it exists into given entity, and if custom function callback is defined it gets to be invoke it.
As example if we have one custom module name: "utitlity" and one date type field named "field_born_date" into an entity definition, and we want to execute any business logic right after get the raw field value, it can looks like this into YML file definition:
properties:
- field_born_date:value:utility_custom_logic
Then into our "utility" module we can create that callback function:
/**
* Callback function to execute after grab first value from field into entity.
*
* @param mixed $value
* Given first value from field into entity.
* @param $entity
* Given entity parsed.
* @param string $field_name
*
* @return mixed
* Final value parsed.
*/
function utility_custom_logic($value, $entity, $field_name) {
// Complex logic to overwrite $value parameter.
$value = uniqid();
// Returns new $value.
return $value;
}
Allow external functions to be called when callback function is invoke inside "getFieldValue()" method.