You are here

function _date_field_widget_settings_form in Date 7.2

Same name and namespace in other branches
  1. 7.3 date_admin.inc \_date_field_widget_settings_form()
  2. 7 date_admin.inc \_date_field_widget_settings_form()

Helper function for date_field_widget_settings_form().

See also

date_field_widget_settings_form_validate()

1 call to _date_field_widget_settings_form()
date_field_widget_settings_form in ./date.field.inc
Implements hook_field_widget_settings_form().

File

./date_admin.inc, line 319
Date administration functionality.

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();
  $options['site-wide'] = t('Short date format: @date', array(
    '@date' => date_format_date($now, 'short'),
  ));
  foreach ($formats as $f) {
    $options[$f] = date_format_date($now, 'custom', $f);
  }
  $form['input_format'] = array(
    '#type' => 'select',
    '#title' => t('Date entry options'),
    '#default_value' => $settings['input_format'],
    '#options' => $options,
    '#description' => t('Control the order and format of the options users see.'),
    '#weight' => 3,
    '#fieldset' => 'date_format',
  );

  // Only a limited set of formats is available for the Date Popup module.
  if ($widget['type'] != 'date_popup') {
    $form['input_format']['#options']['custom'] = t('Custom format');
    $form['input_format_custom'] = array(
      '#type' => 'textfield',
      '#title' => t('Custom input format'),
      '#default_value' => $settings['input_format_custom'],
      '#description' => t("Override the input format selected above. 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',
      )),
      '#weight' => 5,
      '#fieldset' => 'date_format',
      '#attributes' => array(
        'class' => array(
          'indent',
        ),
      ),
      '#states' => array(
        'visible' => array(
          ':input[name="instance[widget][settings][input_format]"]' => array(
            'value' => 'custom',
          ),
        ),
      ),
    );
  }
  else {
    $form['input_format_custom'] = array(
      '#type' => 'hidden',
      '#value' => '',
    );
  }
  if (in_array($widget['type'], array(
    'date_select',
    'date_popup',
  ))) {
    $form['year_range'] = array(
      '#type' => 'date_year_range',
      '#default_value' => $settings['year_range'],
      '#fieldset' => 'date_format',
      '#weight' => 6,
    );
    $form['increment'] = array(
      '#type' => 'select',
      '#title' => t('Time increments'),
      '#default_value' => $settings['increment'],
      '#options' => array(
        1 => t('1 minute'),
        5 => t('5 minute'),
        10 => t('10 minute'),
        15 => t('15 minute'),
        30 => t('30 minute'),
      ),
      '#weight' => 7,
      '#fieldset' => 'date_format',
    );
  }
  else {
    $form['year_range'] = array(
      '#type' => 'hidden',
      '#value' => $settings['year_range'],
    );
    $form['increment'] = array(
      '#type' => 'hidden',
      '#value' => $settings['increment'],
    );
  }
  $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('Advanced settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#fieldset' => 'date_format',
    '#weight' => 9,
  );
  if (in_array($widget['type'], array(
    'date_select',
  ))) {
    $options = array(
      'above' => t('Above'),
      'within' => t('Within'),
      'none' => t('None'),
    );
    $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'Within' inserts the label as the first option in the select list and in blank textfields. 'None' doesn't visually label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
  }
  else {
    $options = array(
      'above' => t('Above'),
      'none' => t('None'),
    );
    $description = t("The location of date part labels, like 'Year', 'Month', or 'Day' . 'Above' displays the label as titles above each date part. 'None' doesn't visually label any of the date parts. Theme functions like 'date_part_label_year' and 'date_part_label_month' control label text.");
  }
  $form['advanced']['label_position'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => $settings['label_position'],
    '#title' => t('Position of date part labels'),
    '#description' => $description,
  );
  $form['advanced']['text_parts'] = array(
    '#theme' => $widget['type'] == 'date_select' ? 'date_text_parts' : NULL,
  );
  $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' => (int) in_array($key, (array) $settings['text_parts']),
      );
    }
  }
  $form['advanced']['no_fieldset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Render as a regular field'),
    '#default_value' => !empty($settings['no_fieldset']),
    '#description' => t('Whether to render this field as a regular field instead of a fieldset. The date field elements are wrapped in a fieldset by default, and may not display well without it.'),
  );
  $context = array(
    'field' => $field,
    'instance' => $instance,
  );

  // Trigger hook_date_field_widget_settings_form_alter().
  drupal_alter('date_field_widget_settings_form', $form, $context);
  return $form;
}