You are here

function mathfield_widget_afterbuild in Math Field 7

Afterbuild callback for the mathfield widgets.

1 string reference to 'mathfield_widget_afterbuild'
mathfield_field_widget_form in ./mathfield.module
Implements hook_field_widget_form().

File

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

Code

function mathfield_widget_afterbuild($element, &$form_state) {

  // Do not add js on the field edit form.
  if ($form_state['build_info']['form_id'] == 'field_ui_field_edit_form') {
    return $element;
  }

  // Add the element parent info for mathfield_widget_validate.
  $form_state['mathfield'][$element['#field_name']] = $element;

  // Add js only once.
  $js_added =& drupal_static(__FUNCTION__ . '_js_added', array());
  if (count($js_added) == 0) {
    drupal_add_js(drupal_get_path('module', 'mathfield') . '/js/mathfield.js');
  }

  // Create js settings for the element.
  if (empty($js_added[$element['#field_name']])) {
    $settings['mathfield'][$element['#field_name']] = array(
      'name' => $element['#name'],
      'tokens' => mathfield_get_tokens($element),
    );
    drupal_add_js($settings, 'setting');
    $js_added[$element['#field_name']] = TRUE;
  }
  return $element;
}