You are here

function mathfield_get_token_values in Math Field 7

Get the submitted values for token replacements.

Parameters

string $element: The math field form element.

array $form_state: The submitted form_state array.

Return value

array An associative array of replacements keyed by token.

2 calls to mathfield_get_token_values()
mathfield_form_afterbuild in ./mathfield.module
Afterbuild callbcak for forms with math expression fields.
_mathfield_evaluate_element in ./mathfield.module
Helper to evaluate a single mathfield element.

File

./mathfield.module, line 595
Adds a dynamic math expression field.

Code

function mathfield_get_token_values($element, $form_state) {
  $replacements = array();
  $expression = $element['#settings']['expression'];
  $tokens = _mathfield_extract_tokens($expression);
  foreach ($tokens as $token => $context) {
    $value = FALSE;
    $field_name = $context['field_name'];
    $field = field_info_field($field_name);
    $context += array(
      'token' => $token,
      'field' => $field,
      'instance' => field_info_instance($element['#entity_type'], $field_name, $element['#bundle']),
      'element' => $element,
      'form_state' => $form_state,
    );

    // Allow other modules to add mathfield support.
    $value = module_invoke($field['module'], 'mathfield_get_token_value', $context);
    drupal_alter(array(
      'mathfield_token_value',
      "mathfield_get_token_value_{$field['module']}",
    ), $value, $context);
    $replacements[$token] = $value;
  }
  return $replacements;
}