1 date.admin.inc _date_field_widget_settings_form($field, $instance)

Helper function for date_field_widget_settings_form().

See also

date_field_widget_settings_form_validate()

File

core/modules/date/date.admin.inc, line 291
Date administration code.

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();
  $formats = system_get_date_formats();
  $formats2 = array();
  foreach ($formats as $entry) {
    // Example input formats should show all possible date parts
    // so add seconds if not already included with minutes
    if (strpos($entry['pattern'], 'i:s')) {
      $formats2[$entry['name']] = $entry['pattern'];
    }
    else {
      $formats2[$entry['name']] = str_replace('i', 'i:s', $entry['pattern']);
    }
  }
  $now = date_now();
  foreach ($formats2 as $f) {
    $options[$f] = date_format_date($now, 'custom', $f) . '  (' . $f . ')';
  }
  $form['input_format'] = array(
    '#type' => 'select',
    '#title' => t('Date entry options'),
    '#default_value' => $settings['input_format'],
    '#options' => $options,
    '#description' => t('Select the preferred format for inputting dates.'),
    '#weight' => 3,
    '#fieldset' => 'date_format',
  );

  if ($widget['type'] === 'date_select') {
    $form['input_format']['#description'] = t('The selected format will determine the order of the date part fields.');
  }

  // 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="http://php.net/date">http://php.net/date</a> for more details).'),
      '#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(
    '#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.");
  }
  else {
    $options = array(
      'none' => t('Hidden'),
      'above' => t('Above'),
    );
    $description = t('The location of date part labels, like "Year", "Month", or "Day" . "Above" displays the label as titles above each date part. "Hidden" doesn\'t visually label any of the date parts.');
  }
  $form['advanced']['label_position'] = array(
    '#type' => 'radios',
    '#options' => $options,
    '#default_value' => $settings['label_position'],
    '#title' => t('Position of date part labels'),
    '#description' => $description,
  );
  if ($widget['type'] == 'date_select') {
    $form['advanced']['text_parts']['#theme'] = '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' => (int) in_array($key, (array) $settings['text_parts']),
      );
    }
  }

  $form['advanced']['no_fieldset'] = array(
    '#type' => 'checkbox',
    '#title' => t('Exclude wrapping fieldset'),
    '#default_value' => !empty($settings['no_fieldset']),
    '#description' => t('If using simple inputs such a a single textfield or the date popup, omitting the fieldset may provide simpler styling.'),
  );

  $context = array(
    'field' => $field,
    'instance' => $instance,
  );
  backdrop_alter('date_field_widget_settings_form', $form, $context);

  return $form;
}