You are here

function _date_field_widget_settings_form in Date 7

Same name and namespace in other branches
  1. 7.3 date_admin.inc \_date_field_widget_settings_form()
  2. 7.2 date_admin.inc \_date_field_widget_settings_form()
1 call to _date_field_widget_settings_form()
date_field_widget_settings_form in ./date.field.inc

File

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

Code

function _date_field_widget_settings_form($field, $instance) {
  $widget = $instance['widget'];
  $settings = $widget['settings'];
  $form = array(
    '#element_validate' => array(
      'date_field_widget_settings_form_validate',
    ),
  );
  $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', array_keys(system_get_date_formats('short')));
    $formats = drupal_map_assoc($formats);
  }
  $now = date_example_date();
  foreach ($formats as $f) {
    $options[$f] = date_format_date($now, 'custom', $f);
  }
  $form['input_format'] = array(
    '#type' => 'select',
    '#title' => t('Input format'),
    '#default_value' => $settings['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.'),
    '#weight' => 4,
  );

  // Only a limited set of formats is available for the Date Popup module
  if ($widget['type'] != 'date_popup') {
    $form['format'] = array(
      '#type' => 'fieldset',
      '#title' => t('Customize Input Format'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => 5,
    );
    $form['format']['input_format_custom'] = array(
      '#type' => 'textfield',
      '#title' => t('Custom input format'),
      '#default_value' => $settings['input_format_custom'],
      '#description' => t("The custom format, if provided, will override the input format selected above. 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 <a href=\"@link\">http://php.net/date</a> for more details).", array(
        '@link' => 'http://php.net/date',
      )),
    );
  }
  else {
    $form['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['year_range'] = array(
      '#type' => 'textfield',
      '#title' => t('Years back and forward'),
      '#default_value' => $settings['year_range'],
      '#size' => 10,
      '#maxsize' => 10,
      '#description' => t('Number of years to go back and forward in the year selection list, default is -3:+3.'),
      '#weight' => 6,
    );
    $form['increment'] = array(
      '#type' => 'select',
      '#title' => t('Time increment'),
      '#default_value' => $settings['increment'],
      '#options' => array(
        1 => 1,
        5 => 5,
        10 => 10,
        15 => 15,
        30 => 30,
      ),
      '#description' => t('Increment the minute and second fields by this amount.'),
      '#weight' => 7,
    );
  }
  else {
    $form['increment'] = array(
      '#type' => 'hidden',
      '#value' => $settings['increment'],
    );
    $form['year_range'] = array(
      '#type' => 'hidden',
      '#value' => $settings['year_range'],
    );
  }
  $form['label_position'] = array(
    '#type' => 'value',
    '#value' => $settings['label_position'],
  );
  $form['text_parts'] = array(
    '#type' => 'value',
    '#value' => $settings['text_parts'],
  );
  $form['advanced'] = array(
    '#type' => 'fieldset',
    '#title' => t('Customize Date Parts'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => 8,
  );
  $form['advanced']['label_position'] = array(
    '#type' => 'radios',
    '#options' => array(
      'above' => t('Above'),
      'within' => t('Within'),
      'none' => t('None'),
    ),
    '#default_value' => $settings['label_position'],
    '#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['advanced']['text_parts'] = array(
    '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : '',
  );
  $text_parts = (array) $settings['text_parts'];
  foreach (date_granularity_names() as $key => $value) {
    if ($widget['type'] == 'date_select') {
      $form['advanced']['text_parts'][$key] = array(
        '#type' => 'radios',
        '#default_value' => in_array($key, $text_parts) ? 1 : 0,
        '#options' => array(
          0 => '',
          1 => '',
        ),
      );
    }
    else {
      $form['advanced']['text_parts'][$key] = array(
        '#type' => 'value',
        '#value' => in_array($key, (array) $settings['text_parts']) ? 1 : 0,
      );
    }
  }
  return $form;
}