function hook_mathfield_get_token_value in Math Field 7
Get the value of a field token for use in a math expression.
This hook is invoked on the module that defines the token's field type. To change the valuefor a field defined in a different module, use hook_mathfield_get_token_value alter() or hook_mathfield_get_token_value_MODULE_alter().
Parameters
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'].
Return value
int|float|bool This hook should return a numeric value to replace the token in the math expression or FALSE if the value could not be determined.
1 function implements hook_mathfield_get_token_value()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- mathfield_mathfield_get_token_value in ./
mathfield.module - Implements hook_mathfield_get_token_value().
1 invocation of hook_mathfield_get_token_value()
- mathfield_get_token_values in ./
mathfield.module - Get the submitted values for token replacements.
File
- ./
mathfield.api.php, line 161 - Hooks provided by Math Field.
Code
function hook_mathfield_get_token_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])) {
return $values[$field_name][$language][$delta][$column];
}
return FALSE;
}