You are here

function partial_date_field_estimates_settings_form in Partial Date 7

Helper function to duplicate the same settings on both the instance and field settings.

1 call to partial_date_field_estimates_settings_form()
partial_date_field_settings_form in ./partial_date.module
Implements hook_field_settings_form().

File

./partial_date.admin.inc, line 86
Less freq. functions for field administration.

Code

function partial_date_field_estimates_settings_form($settings, $field, $instance, $has_data) {
  $form = array();
  $form['estimates'] = array(
    '#type' => 'fieldset',
    '#title' => t('Base estimate values'),
    '#description' => t('These fields provide options for additional fields that can be used to represent corresponding date / time components. They define time periods where an event occured when exact details are unknown. All of these fields have the format "start|end|label", one per line, where start marks when this period started, end marks the end of the period and the label is shown to the user. Instance settings will be used whenever possible on forms, but views integration (once completed) will use the field values. Note that if used, the formatters will replace any corresponding date / time component with the options label value.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  foreach (partial_date_components() as $key => $label) {
    if ($key == 'timezone') {
      continue;
    }
    $value = array();
    if (is_array($settings['estimates'][$key])) {
      foreach ($settings['estimates'][$key] as $range => $option_label) {
        $value[] = $range . '|' . $option_label;
      }
    }
    $form['estimates'][$key] = array(
      '#type' => 'textarea',
      '#title' => t('%label range options', array(
        '%label' => $label,
      ), array(
        'context' => 'datetime settings',
      )),
      '#default_value' => implode("\n", $value),
      '#description' => t('Provide relative approximations for this date / time component.'),
      '#element_validate' => array(
        'partial_date_field_estimates_validate_parse_options',
      ),
      '#date_component' => $key,
    );
  }
  $widget_settings = $instance['widget']['settings'];
  $form['minimum_components'] = array(
    '#type' => 'fieldset',
    '#title' => t('Minimum components'),
    '#description' => t('These are used to determine if the field is incomplete during validation. All possible fields are listed here, but these are only checked if enabled in the instance settings.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $has_range = strpos($field['type'], '_range');
  $options = array();
  foreach (partial_date_components() as $key => $label) {
    $form['minimum_components']['from_granularity_' . $key] = array(
      '#type' => 'checkbox',
      '#title' => $has_range ? t('From @date_component', array(
        '@date_component' => $label,
      )) : $label,
      '#default_value' => !empty($settings['minimum_components']['from_granularity_' . $key]),
    );
  }
  foreach (partial_date_components(array(
    'timezone',
  )) as $key => $label) {
    $form['minimum_components']['from_estimates_' . $key] = array(
      '#type' => 'checkbox',
      '#title' => $has_range ? t('From Estimate @date_component', array(
        '@date_component' => $label,
      )) : t('Estimate @date_component', array(
        '@date_component' => $label,
      )),
      '#default_value' => !empty($settings['minimum_components']['from_estimates_' . $key]),
    );
  }
  if ($field['type'] == 'partial_date_range') {
    foreach (partial_date_components() as $key => $label) {
      $form['minimum_components']['to_granularity_' . $key] = array(
        '#type' => 'checkbox',
        '#title' => t('To @date_component', array(
          '@date_component' => $label,
        )),
        '#default_value' => !empty($settings['minimum_components']['to_granularity_' . $key]),
      );
    }
    foreach (partial_date_components(array(
      'timezone',
    )) as $key => $label) {
      $form['minimum_components']['to_estimates_' . $key] = array(
        '#type' => 'checkbox',
        '#title' => t('To Estimate @date_component', array(
          '@date_component' => $label,
        )),
        '#default_value' => !empty($settings['minimum_components']['to_estimates_' . $key]),
      );
    }
  }
  $form['minimum_components']['txt_short'] = array(
    '#type' => 'checkbox',
    '#title' => t('Short date text'),
    '#default_value' => !empty($settings['minimum_components']['txt_short']),
  );
  $form['minimum_components']['txt_long'] = array(
    '#type' => 'checkbox',
    '#title' => t('Long date text'),
    '#default_value' => !empty($settings['minimum_components']['txt_long']),
  );
  return $form;
}