You are here

function date_tools_wizard_create_date_field in Date 6.2

1 call to date_tools_wizard_create_date_field()
date_tools_wizard_build in date_tools/date_tools.wizard.inc

File

date_tools/date_tools.wizard.inc, line 368
Date Wizard code.

Code

function date_tools_wizard_create_date_field($field_type, $widget_type, $tz_handling, $overrides = array()) {
  date_tools_wizard_include();
  $field_name = $overrides['field_name'];
  $type_name = $overrides['type_name'];

  // Create the date field.
  // Set overrides that apply to all date fields.
  $base_overrides = array(
    'field_name' => $field_name,
    'type_name' => $type_name,
    // Can be set to 0 (none), 1 (unlimited or repeating),
    // or 2-9 for a fixed number of values.
    'multiple' => 0,
    // Set a display format that will show complete date information,
    // to help test that values are correct.
    'default_format' => 'long',
    // Set the date granularity.
    'granularity' => array(
      'year' => 'year',
      'month' => 'month',
      'day' => 'day',
      'hour' => 'hour',
      'minute' => 'minute',
    ),
    // Shall this date include a 'To date'?, can be blank, 'optional', or 'required'
    'todate' => 'optional',
  );

  // Widget overrides:
  $widget_overrides = array(
    // Move the date right below the title.
    'weight' => -4,
    // Set default values to 'blank', 'now', or 'relative'. To dates can also use 'same'.
    'default_value' => 'now',
    'default_value_code' => '',
    // The code to use with 'relative', like '+1 day'.
    'default_value2' => 'blank',
    'default_value_code2' => '',
    // The code to use with 'relative', like '+1 day'.
    // Set format string to use for input forms, it controls order and type of date parts.
    // Input formats must have all date parts, including seconds.
    'input_format_custom' => variable_get('date_format_short', 'm/d/Y - H:i') . ':s',
    // Increment for minutes and seconds, can be 1, 5, 10, 15, or 30.
    'increment' => 15,
    // Optional array of date parts that should be textfields in select widgets,
    // can be any combination of year, month, day, hour, minute, second.
    'text_parts' => array(),
    // The number of years to go back and forward in drop-down year selectors.
    'year_range' => '0:+1',
    // The place for the date part labels, can be 'above', 'within', or 'none'.
    'label_position' => 'above',
  );
  $overrides = array_merge($base_overrides, $overrides);
  $overrides['widget'] = array_merge($widget_overrides, $overrides['widget']);

  // Get field default values for this combination of field and widget type,
  // using a helper function in the Date module.
  $field = date_field_default_values($field_type, $widget_type, $tz_handling, $overrides);
  $field = content_field_instance_collapse($field);
  $field = content_field_instance_create($field);
  $field = content_field_instance_expand($field);
  return $field;
}