You are here

function date_year_range_element_process in Date 7.2

Same name and namespace in other branches
  1. 8 date_api/date_api_elements.inc \date_year_range_element_process()
  2. 7.3 date_api/date_api_elements.inc \date_year_range_element_process()

Process callback which creates a date_year_range form element.

1 string reference to 'date_year_range_element_process'
_date_api_element_info in date_api/date_api_elements.inc
Wrapper for hook_element_info().

File

date_api/date_api_elements.inc, line 154
Date API elements themes and validation.

Code

function date_year_range_element_process($element, &$form_state, $form) {

  // Year range is stored in the -3:+3 format, but collected as two separate
  // textfields.
  $element['years_back'] = array(
    '#type' => 'textfield',
    '#title' => t('Starting year'),
    '#default_value' => $element['#value']['years_back'],
    '#size' => 10,
    '#maxsize' => 10,
    '#attributes' => array(
      'class' => array(
        'select-list-with-custom-option',
        'back',
      ),
    ),
    '#description' => t('Enter a relative value (-9, +9) or an absolute year such as 2015.'),
  );
  $element['years_forward'] = array(
    '#type' => 'textfield',
    '#title' => t('Ending year'),
    '#default_value' => $element['#value']['years_forward'],
    '#size' => 10,
    '#maxsize' => 10,
    '#attributes' => array(
      'class' => array(
        'select-list-with-custom-option',
        'forward',
      ),
    ),
    '#description' => t('Enter a relative value (-9, +9) or an absolute year such as 2015.'),
  );
  $element['#tree'] = TRUE;
  $element['#attached']['js'][] = drupal_get_path('module', 'date_api') . '/date_year_range.js';
  $context = array(
    'form' => $form,
  );

  // Trigger hook_date_year_range_process_alter().
  drupal_alter('date_year_range_process', $element, $form_state, $context);
  return $element;
}