function hook_computed_field_value_alter in Computed Field 3.x
Alter the values of all computed fields.
Parameters
mixed $value: The computed value that can be altered.
array $context: An array containing the 'entity' and 'field_name'.
1 invocation of hook_computed_field_value_alter()
- ComputedFieldHelpers::executeCode in src/
ComputedFieldHelpers.php - Fetches this field's compute function name for implementing elsewhere.
File
- ./
computed_field.api.php, line 16 - API documentation for the Computed Field module.
Code
function hook_computed_field_value_alter(&$value, $context) {
$service = Drupal::service('computed_field.helpers');
// Only proceed when the hook does not exist.
if (!$service
->computeFunctionNameExists($context['field_name'])) {
// Set all unimplemented computed fields to 42.
$value = 42;
}
}