Skip to main content
1 of 2
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

You can implement hook_element_info_alter() to alter the definition of the form element given from system_element_info().

The default definition is the following one:

  $types['date'] = array(
    '#input' => TRUE, 
    '#element_validate' => array('date_validate'), 
    '#process' => array('form_process_date'), 
    '#theme' => 'date', 
    '#theme_wrappers' => array('form_element'),
  );

form_process_date() is the function that set the year sub-element. If you replace it with your own process function, or add it, you can alter that limit.
The code used from the default preprocess function is the following one.

  // Output multi-selector for date.
  foreach ($order as $type) {
    switch ($type) {
      case 'day':
        $options = drupal_map_assoc(range(1, 31));
        $title = t('Day');
        break;

      case 'month':
        $options = drupal_map_assoc(range(1, 12), 'map_month');
        $title = t('Month');
        break;

      case 'year':
        $options = drupal_map_assoc(range(1900, 2050));
        $title = t('Year');
        break;
    }

    $element[$type] = array(
      '#type' => 'select', 
      '#title' => $title, 
      '#title_display' => 'invisible', 
      '#value' => $element['#value'][$type], 
      '#attributes' => $element['#attributes'], 
      '#options' => $options,
    );
  }

As alternative, you can implement hook_preprocess_date(), which is executed when theme_date() is called. (In Drupal 7, every theme function executes preprocess hooks, not just a theme function using a template file.) Doing so, you can alter the form element the preprocess function gets in $variables['element'].

I would rather use the latter method, even though both the methods would work; it is simpler, as it doesn't need to implement two hooks.

avpaderno
  • 97.9k
  • 15
  • 164
  • 284