You are here

function date_field_settings_form in Date 6

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.2 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 333
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',
    ),
  );
  $tz_handling = $field['tz_handling'] ? $field['tz_handling'] : (date_has_time($field['granularity']) ? 'site' : 'none');

  // Override the normal multiple checkbox when using date repeat.
  $options = array(
    0 => t('Never'),
    1 => t('Unlimited'),
  );
  $description = t('Choose an option for handling multiple values. Unlimited will allow the user to manually create unlimited multiple dates one date at a time.');
  $form['repeat'] = array(
    '#type' => 'value',
    '#value' => $field['repeat'],
  );

  // If adding a repeat, override the Content module's handling of the multiple values option.
  if (module_exists('date_repeat')) {
    $form['multiple'] = array(
      '#type' => 'select',
      '#title' => t('Number of values'),
      '#options' => array(
        1 => t('Unlimited'),
        99 => t('Repeating'),
        0 => 1,
      ) + drupal_map_assoc(range(2, 10)),
      '#default_value' => !empty($field['repeat']) ? 99 : $field['multiple'],
      '#description' => t('Select a specific number of values for this field, or \'Unlimited\' to provide an \'Add more\' button so the users can add as many values as they like.  Repeating dates display options to allow the user to select when and how often the date will repeat.') . '<br/><strong>' . t('Warning! Changing this setting after data has been created could result in the loss of data!') . '</strong>',
    );
  }
  $form['input']['todate'] = array(
    '#type' => 'radios',
    '#title' => t('To Date'),
    '#options' => array(
      '' => t('Never'),
      'optional' => t('Optional'),
      'required' => t('Required'),
    ),
    '#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."),
    '#default_value' => $field['todate'] ? $field['todate'] : '',
  );
  $form['input']['granularity'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Granularity'),
    '#default_value' => $field['granularity'] ? $field['granularity'] : array(
      'year',
      'month',
      'day',
      'hour',
      'minute',
    ),
    '#options' => date_granularity_names(),
    '#multiple' => TRUE,
    '#size' => min(count($options), 6),
    '#description' => t('Set the date elements to be stored (at least a year is required).'),
  );
  $form['output']['simple'] = date_formatter_setup_form($field, 0);
  $form['output']['simple']['#title'] = t('Default Display');
  $form['output']['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Additional Display Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Define alternate formatting for the date display. Options other than the default are made available to views and themes. Possible formats are default, long, medium, and short.'),
  );
  for ($i = 1; $i <= 3; $i++) {
    $form['output']['advanced'][$i] = date_formatter_setup_form($field, $i);
  }
  $form['timezone']['tz_handling'] = array(
    '#type' => 'select',
    '#title' => t('Time zone handling'),
    '#default_value' => $tz_handling,
    '#options' => date_timezone_handling_options(),
    '#description' => t('Select the timezone handling method to be used for this date field.'),
  );

  // 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']['timezone_db'] = array(
    '#type' => 'hidden',
    '#value' => 'UTC',
  );
  $form['#suffix'] = t('<div class="form-item"><div class="description">* The custom format, if provided, will override the selected display or input options. Define a php date format string like \'m-d-Y H:i\' (see !link for more details).</div></div>', array(
    '!link' => l('http://php.net/date', 'http://php.net/date'),
  ));
  return $form;
}