You are here

function date_default_value in Date 7.3

Same name and namespace in other branches
  1. 8 date.module \date_default_value()
  2. 5 date.module \date_default_value()
  3. 7.2 date_elements.inc \date_default_value()

The callback for setting a default value for an empty date field.

1 call to date_default_value()
date_field_widget_form in ./date_elements.inc
Private implementation of hook_widget().

File

./date_elements.inc, line 189
Date forms and form themes and validation.

Code

function date_default_value($field, $instance, $langcode) {
  $item = array();
  $db_format = date_type_format($field['type']);
  $date = date_default_value_part($item, $field, $instance, $langcode, 'value');
  $item[0]['value'] = is_object($date) ? date_format($date, $db_format) : '';
  if (!empty($field['settings']['todate'])) {
    $date = date_default_value_part($item, $field, $instance, $langcode, 'value2');
    $item[0]['value2'] = is_object($date) ? date_format($date, $db_format) : '';
  }

  // Make sure the default value has the same construct as a loaded field value
  // to avoid errors if the default value is used on a hidden element.
  $item[0]['timezone'] = date_get_timezone($field['settings']['tz_handling']);
  $item[0]['timezone_db'] = date_get_timezone_db($field['settings']['tz_handling']);
  $item[0]['date_type'] = $field['type'];
  if (!isset($item[0]['value2'])) {
    $item[0]['value2'] = $item[0]['value'];
  }
  return $item;
}