1 date.field.inc date_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base)

Implementation of hook_field_widget_form().

The widget builds out a complex date element in the following way:

  • A field is pulled out of the database which is comprised of one or more collections of start/end dates.
  • The dates in this field are all converted from the UTC values stored in the database back to the local time. This is done in #process to avoid making this change to dates that are not being processed, like those hidden with #access.
  • If values are empty, the field settings rules are used to determine if the default_values should be empty, now, the same, or use strtotime.
  • Each start/end combination is created using the date_combo element type defined by the date module. If the timezone is date-specific, a timezone selector is added to the first combo element.
  • The date combo element creates two individual date elements, one each for the start and end field, using the appropriate individual Date API date elements, like selects, textfields, or popups.
  • In the individual element validation, the data supplied by the user is used to update the individual date values.
  • In the combo date validation, the timezone is updated, if necessary, then the user input date values are used with that timezone to create date objects, which are used update combo date timezone and offset values.
  • In the field's submission processing, the new date values, which are in the local timezone, are converted back to their UTC values and stored.


core/modules/date/date.field.inc, line 354
Field hooks to implement a date field.


function date_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
  module_load_include('inc', 'date', 'date.elements');

  switch ($instance['widget']['type']) {
    case 'date_html5':
      if (!isset($form['#entity'])) {
        // Prevent additional default value and useless token browser on the
        // settings form.
        $form['#access'] = FALSE;
      $element = _date_html5_field_widget_form($field, $instance, $langcode, $items, $delta, $base);

      $element = _date_default_field_widget_form($field, $instance, $langcode, $items, $delta, $base);

  return $element;