You are here

function _webform_render_date in Webform 7.4

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

Implements _webform_render_component().

File

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

Code

function _webform_render_date($component, $value = NULL, $filter = TRUE, $submission = NULL) {
  $node = isset($component['nid']) ? node_load($component['nid']) : NULL;
  $element = array(
    '#type' => 'date',
    '#title' => $filter ? webform_filter_xss($component['name']) : $component['name'],
    '#title_display' => $component['extra']['title_display'] ? $component['extra']['title_display'] : 'before',
    '#weight' => $component['weight'],
    '#description' => $filter ? webform_filter_descriptions($component['extra']['description'], $node) : $component['extra']['description'],
    '#required' => $component['required'],
    '#start_date' => trim($component['extra']['start_date']),
    '#end_date' => trim($component['extra']['end_date']),
    '#reference_timestamp' => $submission && $submission->completed ? $submission->completed : NULL,
    '#year_textfield' => $component['extra']['year_textfield'],
    '#default_value' => $filter ? webform_replace_tokens($component['value'], $node) : $component['value'],
    '#timezone' => $component['extra']['timezone'],
    '#exclude' => $component['extra']['exclude'],
    '#process' => array(
      'webform_expand_date',
    ),
    '#theme' => 'webform_date',
    '#theme_wrappers' => array(
      'webform_element',
    ),
    '#element_validate' => array(
      'webform_validate_date',
    ),
    '#translatable' => array(
      'title',
      'description',
    ),
  );
  if ($component['extra']['datepicker']) {
    $element['#datepicker'] = TRUE;
    $element['#attached'] = array(
      'library' => array(
        array(
          'system',
          'ui.datepicker',
        ),
      ),
    );
  }

  // Set the value from Webform.
  if (isset($value[0]) && $value[0] !== '') {
    $value = webform_date_array($value[0], 'date');
    $element['#default_value'] = $value;
  }
  return $element;
}