You are here

function theme_webform_date in Webform 7.4

Same name and namespace in other branches
  1. 5 components/date.inc \theme_webform_date()
  2. 6.3 components/date.inc \theme_webform_date()
  3. 7.3 components/date.inc \theme_webform_date()

Theme a webform date element.

1 theme call to theme_webform_date()
_webform_render_date in components/date.inc
Implements _webform_render_component().

File

components/date.inc, line 359
Webform module date component.

Code

function theme_webform_date($variables) {
  $element = $variables['element'];
  $element['year']['#attributes']['class'][] = 'year';
  $element['month']['#attributes']['class'][] = 'month';
  $element['day']['#attributes']['class'][] = 'day';

  // Add error classes to all items within the element.
  if (form_get_error($element)) {
    $element['year']['#attributes']['class'][] = 'error';
    $element['month']['#attributes']['class'][] = 'error';
    $element['day']['#attributes']['class'][] = 'error';
  }

  // Add HTML5 required attribute, if needed.
  if ($element['#required']) {
    $element['year']['#attributes']['required'] = 'required';
    $element['month']['#attributes']['required'] = 'required';
    $element['day']['#attributes']['required'] = 'required';
  }
  $class = array(
    'webform-container-inline',
  );

  // Add the JavaScript calendar if available (provided by Date module package).
  if (!empty($element['#datepicker'])) {
    $class[] = 'webform-datepicker';
    $calendar_class = array(
      'webform-calendar',
    );
    if ($element['#start_date']) {
      $calendar_class[] = 'webform-calendar-start-' . $element['#start_date'];
    }
    if ($element['#end_date']) {
      $calendar_class[] = 'webform-calendar-end-' . $element['#end_date'];
    }
    $calendar_class[] = 'webform-calendar-day-' . variable_get('date_first_day', 0);
    $calendar = theme('webform_calendar', array(
      'component' => $element['#webform_component'],
      'calendar_classes' => $calendar_class,
    ));
  }
  $output = '';
  $output .= '<div class="' . implode(' ', $class) . '">';
  $output .= drupal_render_children($element);
  $output .= isset($calendar) ? $calendar : '';
  $output .= '</div>';
  return $output;
}