You are here

function birthdays_process_date in Birthdays 7

Render API callback: Expands the birthdays_date element.

This function is assigned as a #process callback in birthdays_element_info().

1 string reference to 'birthdays_process_date'
birthdays_element_info in ./birthdays.module
Implements hook_element_info().

File

./birthdays.module, line 154
The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an email on their birthday automatically, and the administrator can receive daily reminders of…

Code

function birthdays_process_date($element) {
  $element['#tree'] = TRUE;

  // Default value for the #year property.
  if (!isset($element['#year'])) {
    $element['#year'] = BIRTHDAYS_HIDE_YEAR_NO;
  }

  // Default value for the #display property.
  if (!isset($element['#display']['dateformat'])) {
    $element['#display']['dateformat'] = 'Y/m/d';
  }
  if (!isset($element['#display']['dateformat_noyear'])) {
    $element['#display']['dateformat_noyear'] = 'M d';
  }

  // There is a select box for month, day and maybe for year. Determine which to
  // display and the order.
  $types = array();
  if ($element['#year'] == BIRTHDAYS_HIDE_YEAR_YES) {
    $element['year'] = array(
      '#type' => 'hidden',
      '#value' => 0,
    );
    $format = $element['#display']['dateformat_noyear'];
  }
  else {
    $format = $element['#display']['dateformat'];
    $types['year'] = max(strpos($format, 'Y'), strpos($format, 'y'));
  }
  $types['month'] = max(strpos($format, 'M'), strpos($format, 'm'));
  $types['day'] = max(strpos($format, 'd'), strpos($format, 'j'));
  asort($types);
  foreach ($types as $type => $pos) {
    $element[$type] = array(
      '#type' => 'select',
      '#title_display' => 'invisible',
      '#options' => array(
        0 => '',
      ),
    );
    if (isset($element['#value'][$type])) {
      $element[$type]['#value'] = $element['#value'][$type];
    }
    switch ($type) {
      case 'month':
        $element[$type]['#title'] = t('Month');
        $element[$type]['#options'] += drupal_map_assoc(range(1, 12), 'map_month');
        break;
      case 'day':
        $element[$type]['#title'] = t('Day');
        $element[$type]['#options'] += drupal_map_assoc(range(1, 31));
        break;
      case 'year':
        $element[$type]['#title'] = t('Year');
        $element[$type]['#options'] += drupal_map_assoc(range(1900, date('Y', REQUEST_TIME)));
        if ($element['#year'] == BIRTHDAYS_HIDE_YEAR_USER) {
          $element[$type]['#options'][0] = t('optional');
        }
        break;
    }
  }
  return $element;
}