You are here

function date_widget_settings_form in Date 5.2

Same name and namespace in other branches
  1. 5 date_admin.inc \date_widget_settings_form()
  2. 6.2 date/date_admin.inc \date_widget_settings_form()
  3. 6 date/date_admin.inc \date_widget_settings_form()
1 call to date_widget_settings_form()
_date_widget_settings in date/date_admin.inc
Implementation of hook_widget_settings().

File

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

Code

function date_widget_settings_form($widget) {
  $form = array();
  $form['input']['default_value'] = array(
    '#type' => 'radios',
    '#title' => t('Default value'),
    '#default_value' => !empty($widget['default_value']) ? $widget['default_value'] : 'blank',
    '#options' => array(
      'blank' => t('Blank'),
      'now' => t('Now'),
      'strtotime' => t('Relative'),
    ),
    '#description' => t("A default value to use for this field. If you select 'Relative', add details below."),
  );
  $form['input']['default'] = array(
    '#type' => 'fieldset',
    '#title' => t('Customize Default Value'),
    '#description' => t("<p>The custom value for a Relative default should be something that describes a time by reference to the current day using strtotime, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See !strtotime for more details.</p>", array(
      '!strtotime' => l(t('strtotime'), 'http://www.php.net/manual/en/function.strtotime.php'),
    )),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['input']['default']['default_value_code'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom value for From date'),
    '#default_value' => isset($widget['default_value_code']) ? $widget['default_value_code'] : '',
  );
  $form['input']['default']['default_value2'] = array(
    '#type' => 'radios',
    '#title' => t('Default value for To date'),
    '#default_value' => !empty($widget['default_value2']) ? $widget['default_value2'] : 'same',
    '#options' => array(
      'same' => t('Same as From date'),
      'blank' => t('Blank'),
      'now' => t('Now'),
      'strtotime' => t('Relative'),
    ),
    '#description' => t("A default value to use for this field. If you select 'Relative', add details below."),
  );
  $form['input']['default']['default_value_code2'] = array(
    '#type' => 'textfield',
    '#title' => t('Custom value for To date'),
    '#default_value' => isset($widget['default_value_code2']) ? $widget['default_value_code2'] : '',
  );
  $options = array();
  if ($widget['type'] == 'date_popup' && module_exists('date_popup')) {
    $formats = date_popup_formats();
  }
  else {

    // example input formats must show all possible date parts, so add seconds.
    $formats = str_replace('i', 'i:s', date_short_formats());
    $formats = drupal_map_assoc($formats);
  }
  $now = date_example_date();
  foreach ($formats as $f) {
    $options[$f] = date_format_date($now, 'custom', $f);
  }
  $form['input']['input_format'] = array(
    '#type' => 'select',
    '#title' => t('Input format'),
    '#default_value' => $widget['input_format'],
    '#options' => $options,
    '#description' => t('Set the order and format for the date parts in the input form. The format will be adapted to remove values not in the granularity for this field.'),
  );

  // Only a limited set of formats is available for the Date Popup module
  if ($widget['type'] != 'date_popup') {
    $form['input']['format']['input_format_custom'] = array(
      '#type' => 'textfield',
      '#title' => t('*Custom input format'),
      '#default_value' => $widget['input_format_custom'] ? $widget['input_format_custom'] : '',
      '#description' => t('The custom format, if provided, will override the input format selected above. See more about custom date formats below.'),
    );
  }
  else {
    $form['input']['format']['input_format_custom'] = array(
      '#type' => 'hidden',
      '#value' => '',
    );
  }
  if (in_array($widget['type'], array(
    'date_select',
    'date_popup',
    'date_select_repeat',
    'date_popup_repeat',
  ))) {
    $form['input']['year_range'] = array(
      '#type' => 'textfield',
      '#title' => t('Years back and forward'),
      '#default_value' => !empty($widget['year_range']) ? $widget['year_range'] : '-3:+3',
      '#size' => 10,
      '#maxsize' => 10,
      '#description' => t('Number of years to go back and forward in the year selection list, default is -3:+3.'),
    );
    $form['input']['increment'] = array(
      '#type' => 'select',
      '#title' => t('Time increment'),
      '#default_value' => isset($widget['increment']) ? $widget['increment'] : 1,
      '#options' => array(
        1 => 1,
        5 => 5,
        10 => 10,
        15 => 15,
        30 => 30,
      ),
      '#description' => t('Increment the minute and second fields by this amount.'),
    );
  }
  else {
    $form['increment'] = array(
      '#type' => 'hidden',
      '#value' => !empty($widget['increment']) ? $widget['increment'] : 1,
    );
    $form['year_range'] = array(
      '#type' => 'hidden',
      '#value' => isset($widget['year_range']) ? $widget['year_range'] : '-3:+3',
    );
  }
  $form['input']['advanced'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => t('Customize Date Parts'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['input']['advanced']['label_position'] = array(
    '#type' => 'radios',
    '#options' => array(
      'above' => t('Above'),
      'within' => t('Within'),
      'none' => t('None'),
    ),
    '#default_value' => !empty($widget['label_position']) ? $widget['label_position'] : 'above',
    '#title' => t('Position of date part labels'),
    '#description' => t('The location of date part labels, like \'Year\', \'Month\', or \'Day\'. \'Above\' will display them as titles above each date part. \'Within\' will insert the label as the first option in the select list and in blank textfields. \'None\' will not label any of the date parts. The exact text in the label is controlled by themes like \'date_part_label_year\' and \'date_part_label_month\'.'),
  );
  $form['input']['advanced']['text_parts'] = array(
    '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts_theme' : '',
  );
  foreach (date_granularity_names() as $key => $value) {
    if ($widget['type'] == 'date_select') {
      $form['input']['advanced']['text_parts'][$key] = array(
        '#type' => 'radios',
        '#default_value' => in_array($key, (array) $widget['text_parts']) ? 1 : 0,
        '#options' => array(
          0 => '',
          1 => '',
        ),
      );
    }
    else {
      $form['input']['advanced']['text_parts'][$key] = array(
        '#type' => 'hidden',
        '#value' => in_array($key, (array) $widget['text_parts']) ? 1 : 0,
      );
    }
  }
  return $form;
}