You are here

function interval_element_process in Interval Field 7

Process function to expand the interval element type.

1 string reference to 'interval_element_process'
interval_element_info in ./interval.module
Implements hook_element_info().

File

./interval.module, line 310
Defines an interval field @copyright Copyright(c) 2011 Rowlands Group @license GPL v2+ http://www.fsf.org/licensing/licenses/gpl.html @author Lee Rowlands leerowlands at rowlandsgroup dot com

Code

function interval_element_process($element, &$form_state, $form) {
  $value = !empty($element['#default_value']) ? $element['#default_value'] : array(
    'interval' => NULL,
    'period' => NULL,
  );
  $element['interval'] = array(
    '#type' => 'textfield',
    '#default_value' => $value['interval'],
    '#required' => $element['#required'],
  );
  $intervals = interval_get_intervals();
  $periods = !empty($element['#periods']) ? $element['#periods'] : array_keys($intervals);
  $period_options = array();
  foreach ($intervals as $key => $detail) {
    if (in_array($key, $periods) && isset($detail['plural'])) {
      $period_options[$key] = $detail['plural'];
    }
  }
  $element['period'] = array(
    '#type' => 'select',
    '#options' => $period_options,
    '#default_value' => $value['period'],
    '#required' => $element['#required'],
  );
  return $element;
}