You are here

function hook_mathfield_get_token_value_alter in Math Field 7

Alter the value of a field token for use in a math expression.

This hook allows other modules to change the replacement value of a token for a field type defined in other modules. The source module may be found in $context['field']['module'].

Parameters

int|float|bool $value: The current numeric value of the field or FALSE.

array $context: An associative array with the following keys:

  • 'field_name': The machine name of the token field.
  • 'delta': The delta value of the token field for multivalue fields. Default is 0.
  • 'column': The source column of the token field. Default is 'value'.
  • 'token': The token used in the math expression.
  • 'field': The field definition of the token field.
  • 'instance': The field instance definition of the token field.
  • 'element': The mathfield form element.
  • 'form_state' The entire form_state array including submitted values. The token value is usually extracted from $context['form_state']['values'].

File

./mathfield.api.php, line 197
Hooks provided by Math Field.

Code

function hook_mathfield_get_token_value_alter(&$value, $context) {
  $values = $context['form_state']['values'];
  $field_name = $context['field_name'];
  $language = $context['element']['#language'];
  $delta = $context['delta'];
  $column = $context['column'];
  if (isset($values[$field_name][$language][$delta][$column]) && is_numeric($values[$field_name][$language][$delta][$column])) {
    $value = $values[$field_name][$language][$delta][$column];
  }
}