You are here

function rules_ui_element_duration_process in Rules 7.2

FAPI process callback for the duration element type.

1 string reference to 'rules_ui_element_duration_process'
rules_element_info in ./rules.module
Implements hook_element_info().

File

ui/ui.forms.inc, line 760
Rules User Interface forms.

Code

function rules_ui_element_duration_process($element, &$form_state) {
  $element['value'] = array(
    '#type' => 'textfield',
    '#size' => 8,
    '#element_validate' => array(
      'rules_ui_element_integer_validate',
    ),
    '#default_value' => $element['#default_value'],
    '#required' => !empty($element['#required']),
  );
  $element['multiplier'] = array(
    '#type' => 'select',
    '#options' => rules_ui_element_duration_multipliers(),
    '#default_value' => 1,
  );

  // Put the child elements in a container-inline div.
  $element['value']['#prefix'] = '<div class="rules-duration container-inline">';
  $element['multiplier']['#suffix'] = '</div>';

  // Set an appropriate multiplier.
  if (!empty($element['value']['#default_value'])) {
    foreach (array_keys(rules_ui_element_duration_multipliers()) as $m) {
      if ($element['value']['#default_value'] % $m == 0) {
        $element['multiplier']['#default_value'] = $m;
      }
    }

    // Divide value by the multiplier, so the display is correct.
    $element['value']['#default_value'] /= $element['multiplier']['#default_value'];
  }
  return $element;
}