You are here

function units_mathematical_expression_element_process in Units of Measurement 7.2

Process function for 'units_mathematical_expression' form element.

1 string reference to 'units_mathematical_expression_element_process'
units_element_info in ./units.module
Implements hook_element_info().

File

./units.module, line 817
Provide API for managing and converting units of measurement.

Code

function units_mathematical_expression_element_process($element) {
  $element['#tree'] = TRUE;
  $blacklist = array(
    '#type',
    '#element_validate',
    // Make form_builder() regenerate child properties.
    '#parents',
    '#id',
    '#name',
    // Do not copy this #process function to prevent form_builder() from
    // recursing infinitely.
    '#process',
    // Ensure proper ordering of children.
    '#weight',
    // Properties already processed for the parent element.
    '#prefix',
    '#suffix',
    '#attached',
    '#processed',
    '#theme_wrappers',
    // Force form_builder() to load defaults for all children.
    '#defaults_loaded',
    '#value',
  );

  // Move this element into sub-element 'infix'.
  unset($element['infix']);
  foreach (element_properties($element) as $key) {
    if (!in_array($key, $blacklist)) {
      $element['infix'][$key] = $element[$key];
    }
  }
  $element['infix']['#type'] = 'textfield';
  if (isset($element['infix']['#default_value']) && is_object($element['infix']['#default_value'])) {
    $element['infix']['#default_value'] = $element['infix']['#default_value']
      ->getExpression()
      ->toInfix();
  }
  return $element;
}