You are here

function _partial_date_field_widget_settings_form in Partial Date 7

Implements hook_field_widget_settings_form().

1 call to _partial_date_field_widget_settings_form()
partial_date_field_widget_settings_form in ./partial_date.module
Implements hook_field_widget_settings_form().

File

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

Code

function _partial_date_field_widget_settings_form($field, $instance) {
  $settings = $instance['widget']['settings'];
  $has_range = strpos($field['type'], 'range');
  $form = array();
  $options = partial_date_components();
  $form['granularity'] = array(
    '#tree' => TRUE,
  );
  $form['granularity']['from'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Date components'),
    '#default_value' => $settings['granularity']['from'],
    '#options' => $options,
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#description' => t('Select the date attributes to collect and store.'),
    '#weight' => -10,
  );
  $form['estimates'] = array(
    '#tree' => TRUE,
  );
  $form['estimates']['from'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Date component estimates'),
    '#default_value' => $settings['estimates']['from'],
    '#options' => $options,
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#description' => t('Select the date component estimate attributes that you want to expose.'),
    '#weight' => -9,
  );
  unset($form['estimates']['from']['#options']['timezone']);
  if ($has_range) {
    $form['granularity']['to'] = $form['granularity']['from'];
    $form['granularity']['to']['#title'] = t('Date components (to date)');
    $form['granularity']['to']['#default_value'] = $settings['granularity']['to'];
    $form['granularity']['to']['#weight'] = -8;
    $form['granularity']['from']['#title'] = t('Date components (from date)');
    $form['estimates']['to'] = $form['estimates']['from'];
    $form['estimates']['to']['#title'] = t('Date component estimates (to date)');
    $form['estimates']['to']['#default_value'] = $settings['estimates']['to'];
    $form['estimates']['to']['#weight'] = -7;
    $form['estimates']['from']['#title'] = t('Date component estimates (from date)');
  }
  $tz_options = partial_date_timezone_handling_options();
  $form['tz_handling'] = array(
    '#type' => 'select',
    '#title' => t('Time zone handling'),
    '#default_value' => $settings['tz_handling'],
    '#options' => $tz_options,
    '#required' => TRUE,
    '#weight' => -6,
    '#description' => t('Select the timezone handling method for this field. Currently, this is only used to calculate the timestamp that is store in the database. This determines the sorting order when using views integration. Only %none and %date handling options will render the timezone selector to users.', array(
      '%none' => $tz_options['none'],
      '%date' => $tz_options['date'],
    )),
  );
  $form['increments'] = array();
  $form['increments']['minute'] = array(
    '#type' => 'select',
    '#title' => t('Minute increments'),
    '#default_value' => empty($settings['increments']['minute']) ? 1 : $settings['increments']['minute'],
    '#options' => drupal_map_assoc(array(
      1,
      2,
      5,
      10,
      15,
      30,
    )),
    '#required' => TRUE,
    '#weight' => -7,
  );
  $form['increments']['second'] = array(
    '#type' => 'select',
    '#title' => t('Second increments'),
    '#default_value' => empty($settings['increments']['second']) ? 1 : $settings['increments']['second'],
    '#options' => drupal_map_assoc(array(
      1,
      2,
      5,
      10,
      15,
      30,
    )),
    '#required' => TRUE,
    '#weight' => -7,
  );
  $form['theme_overrides'] = array(
    '#tree' => TRUE,
  );
  $form['theme_overrides']['txt_short'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide a textfield for collection of a short description of the date'),
    '#default_value' => $settings['theme_overrides']['txt_short'],
    '#weight' => -5,
  );
  $form['theme_overrides']['txt_long'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide a textfield for collection of a long description of the date'),
    '#default_value' => $settings['theme_overrides']['txt_long'],
    '#weight' => -4,
  );
  $form['theme_overrides']['check_approximate'] = array(
    '#type' => 'checkbox',
    '#title' => t('Provide a checkbox to specify that the date is approximate'),
    '#default_value' => !empty($settings['theme_overrides']['check_approximate']),
    '#weight' => -3,
  );
  $form['theme_overrides']['range_inline'] = array(
    '#type' => 'checkbox',
    '#title' => t('Theme range widgets to be rendered inline.'),
    '#default_value' => $has_range ? !empty($settings['theme_overrides']['range_inline']) : 0,
    '#weight' => 0,
    '#access' => $has_range,
  );
  $form['hide_remove'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide the %remove checkbox', array(
      '%remove' => t('Remove date', array(), array(
        'context' => 'datetime',
      )),
    )),
    '#default_value' => !empty($settings['hide_remove']),
  );
  $form['help_txt'] = array(
    '#tree' => TRUE,
    '#type' => 'fieldset',
    '#title' => t('Inline help'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('This provides additional help per component, or a way to override the default description text.<br/>Allowed HTML tags: @tags', array(
      '@tags' => _field_filter_xss_display_allowed_tags(),
    )),
  );

  // Hide all bar current language.
  $current_langcode = LANGUAGE_NONE;
  if (!isset($settings['help_txt'])) {
    $settings['help_txt'] = array();
  }
  foreach ($settings['help_txt'] as $langcode => $values) {
    if ($current_langcode == $langcode) {
      continue;
    }
    foreach ($values as $index => $value) {
      $settings['help_txt'][$langcode][$index] = array(
        '#type' => 'value',
        '#value' => $value,
      );
    }
  }
  $help_txt = _partial_date_widget_help_text($instance, $current_langcode);
  $form['help_txt'][$current_langcode]['components'] = array(
    '#type' => 'textarea',
    '#title' => t('Date components'),
    '#default_value' => $help_txt['components'],
    '#rows' => 3,
    '#description' => t('Instructions to present under the date or date range components. No help shown by default.'),
  );
  $form['help_txt'][$current_langcode]['check_approximate'] = array(
    '#type' => 'textarea',
    '#title' => t('Date approximate checkbox'),
    '#default_value' => $help_txt['check_approximate'],
    '#rows' => 3,
    '#description' => t('Instructions to present under the approximate checkbox if used. No help shown by default.'),
  );
  $form['help_txt'][$current_langcode]['txt_short'] = array(
    '#type' => 'textarea',
    '#title' => t('Short date description'),
    '#default_value' => $help_txt['txt_short'],
    '#rows' => 3,
    '#description' => t('Instructions to present under the short date description if used. Default is %default', array(
      '%default' => t('Short date description'),
    )),
  );
  $form['help_txt'][$current_langcode]['txt_long'] = array(
    '#type' => 'textarea',
    '#title' => t('Long date description'),
    '#default_value' => $help_txt['txt_long'],
    '#rows' => 3,
    '#description' => t('Instructions to present under the long date description if used. Default is %default', array(
      '%default' => t('Longer description of date'),
    )),
  );
  $form['help_txt'][$current_langcode]['_remove'] = array(
    '#type' => 'textarea',
    '#title' => t('Remove checkbox'),
    '#default_value' => $help_txt['_remove'],
    '#rows' => 3,
    '#description' => t('Instructions to present under the remove checkbox if shown. No help shown by default.'),
  );
  return $form;
}