You are here

function date_field_settings_form in Date 6.2

Same name and namespace in other branches
  1. 8 date.field.inc \date_field_settings_form()
  2. 5.2 date/date_admin.inc \date_field_settings_form()
  3. 5 date_admin.inc \date_field_settings_form()
  4. 6 date/date_admin.inc \date_field_settings_form()
  5. 7.3 date.field.inc \date_field_settings_form()
  6. 7 date.field.inc \date_field_settings_form()
  7. 7.2 date.field.inc \date_field_settings_form()
1 call to date_field_settings_form()
_date_field_settings in date/date_admin.inc
Implementation of hook_field_settings().

File

date/date_admin.inc, line 326
Date administration code. Moved to separate file since there is a lot of code here that is not needed often.

Code

function date_field_settings_form($field) {
  $form = array(
    '#element_validate' => array(
      'date_field_settings_validate',
    ),
  );

  // Make sure granularity is in the right format and has no empty values.
  if (!empty($field['granularity']) && is_array($field['granularity'])) {
    $granularity = array_filter($field['granularity']);
  }
  else {
    $granularity = array(
      'year',
      'month',
      'day',
      'hour',
      'minute',
    );
  }
  $tz_handling = isset($field['tz_handling']) ? $field['tz_handling'] : (date_has_time($granularity) ? 'site' : 'none');

  // If adding a repeat, override the Content module's handling of the multiple values option.
  if (module_exists('date_repeat') && date_is_repeat_field($field)) {
    $form['multiple'] = array(
      '#type' => 'hidden',
      '#value' => 1,
    );
    $form['repeat'] = array(
      '#type' => 'hidden',
      '#value' => 1,
    );
  }
  else {
    $form['repeat'] = array(
      '#type' => 'hidden',
      '#value' => 0,
    );
  }
  $description = t("Display a matching second date field as a 'To date'. If marked 'Optional' field will be presented but not required. If marked 'Required' the 'To date' will be required if the 'From date' is required or filled in.");
  $description .= date_data_loss_warning('To date');
  $form['input']['todate'] = array(
    '#type' => 'radios',
    '#title' => t('To Date'),
    '#options' => array(
      '' => t('Never'),
      'optional' => t('Optional'),
      'required' => t('Required'),
    ),
    '#description' => $description,
    '#default_value' => isset($field['todate']) ? $field['todate'] : '',
  );
  $form['input']['granularity'] = array(
    '#type' => 'select',
    '#title' => t('Granularity'),
    '#default_value' => $granularity,
    '#options' => date_granularity_names(),
    '#multiple' => TRUE,
    '#description' => t('Set the date elements to be stored (at least a year is required).'),
  );
  $format_types = array();
  foreach (date_get_format_types('', TRUE) as $name => $info) {
    $format_types[$name] = $info['title'];
  }
  $form['default_format'] = array(
    '#type' => 'select',
    '#title' => t('Default Display'),
    '#default_value' => !empty($field['default_format']) ? $field['default_format'] : 'medium',
    '#options' => $format_types,
    '#description' => t('Select a default format type to be used for the date display. Visit the <a href="@date-time-page">Date and time date format page</a> to add and edit format types.', array(
      '@date-time-page' => url('admin/settings/date-time/formats'),
    )),
  );
  $description = t('Select the timezone handling method to be used for this date field.');
  $description .= date_data_loss_warning('Time zone handling');
  $form['tz_handling'] = array(
    '#type' => 'select',
    '#title' => t('Time zone handling'),
    '#default_value' => $tz_handling,
    '#options' => date_timezone_handling_options(),
    '#description' => $description,
  );

  // Force this value to hidden because we don't want to allow it to be changed right now,
  // but allow it to be a variable if needed.
  $form['timezone_db'] = array(
    '#type' => 'hidden',
    '#value' => date_get_timezone_db($tz_handling),
  );
  if (module_exists('date_repeat') && date_is_repeat_field($field)) {
    $form['repeat_collapsed'] = array(
      '#type' => 'radios',
      '#default_value' => !empty($field['repeat_collapsed']) ? intval($field['repeat_collapsed']) : 0,
      '#options' => array(
        0 => t('Expanded'),
        1 => t('Collapsed'),
      ),
      '#title' => t('Repeat display'),
      '#description' => t("Should the repeat options form start out expanded or collapsed? Set to 'Collapsed' to make those options less obtrusive."),
    );
  }
  return $form;
}