You are here

function field_timer_field_widget_form in Field Timer 7.2

Same name and namespace in other branches
  1. 7 field_timer.module \field_timer_field_widget_form()

Implements hook_field_widget_form().

File

./field_timer.module, line 97
Main module file.

Code

function field_timer_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch ($instance['widget']['type']) {
    case 'field_timer_simple_date':
      $default_value = NULL;

      // Default value from database is timestamp, default value set by admin
      // at field configuration page is formatted date string.
      if (isset($items[$delta]['timestamp'])) {
        if (is_numeric($items[$delta]['timestamp'])) {
          $default_value = date('Y-m-d H:i:s', $items[$delta]['timestamp']);
        }
        else {
          $default_value = $items[$delta]['timestamp'];
        }
      }
      $widget = array(
        '#type' => 'date_popup',
        '#title' => $element['#title'],
        '#default_value' => $default_value,
      );
      $element['timestamp'] = $widget;
      break;
  }
  return $element;
}