function mathfield_mathfield_get_token_value_list_alter in Math Field 7
Implements hook_mathfield_get_token_value_MODULE_alter() for the list.module.
Related topics
File
- ./
mathfield.module, line 757 - Adds a dynamic math expression field.
Code
function mathfield_mathfield_get_token_value_list_alter(&$value, $context) {
// Only support numeric list types.
if (!in_array($context['field']['type'], array(
'list_integer',
'list_float',
))) {
return;
}
// @todo: Support multivalue fields.
if ($context['field']['cardinality'] != 1 || $context['delta'] > 0) {
return;
}
$values = $context['form_state']['values'];
$field_name = $context['field_name'];
$language = $context['element']['#language'];
$delta = $context['delta'];
$column = $context['column'];
// List value is at $values[$field_name][$language] on initial form load and
// $values[$field_name][$language][$delta][$column] on form submission.
if (isset($values[$field_name][$language]) && is_numeric($values[$field_name][$language])) {
$value = $values[$field_name][$language];
}
elseif (isset($values[$field_name][$language][$delta][$column]) && is_numeric($values[$field_name][$language][$delta][$column])) {
$value = $values[$field_name][$language][$delta][$column];
}
}