You are here

function _date_field_settings_form in Date 8

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

Helper function for date_field_settings_form().

See also

date_field_settings_validate()

1 call to _date_field_settings_form()
date_field_settings_form in ./date.field.inc
Implements hook_field_settings_form().

File

./date_admin.inc, line 109
Date administration code.

Code

function _date_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];
  $form = array(
    '#element_validate' => array(
      'date_field_settings_validate',
    ),
  );

  // Make sure granularity is in the right format and has no empty values.
  if (!empty($settings['granularity']) && is_array($settings['granularity'])) {
    $granularity = array_filter($settings['granularity']);
  }
  $tz_handling = $settings['tz_handling'];
  $description = t('Select the date attributes to collect and store.');
  $options = DateGranularity::granularityNames();
  $checkbox_year = array(
    '#type' => 'checkbox',
    '#title' => check_plain($options['year']),
    '#value' => 'year',
    '#return_value' => 'year',
    '#disabled' => TRUE,
  );
  unset($options['year']);
  $form['granularity'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Date attributes to collect'),
    '#default_value' => $granularity,
    '#options' => $options,
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#description' => $description,
    '#disabled' => $has_data,
    'year' => $checkbox_year,
  );
  $description = t('End dates are used to collect duration. E.g., allow an event to start on September 15, and end on September 16.');
  $form['enddate_get'] = array(
    '#type' => 'checkbox',
    '#title' => t('Collect an end date'),
    '#description' => $description,
    '#default_value' => empty($settings['todate']) ? FALSE : TRUE,
    '#disabled' => $has_data,
  );
  $form['enddate_required'] = array(
    '#type' => 'checkbox',
    '#title' => t('Required'),
    '#default_value' => isset($settings['todate']) && $settings['todate'] === 'required' ? TRUE : FALSE,
    '#disabled' => $has_data,
    '#states' => array(
      'invisible' => array(
        'input[name="field[settings][enddate_get]"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );
  $description = t('Select the timezone handling method for this date field.');
  $form['tz_handling'] = array(
    '#type' => 'select',
    '#title' => t('Time zone handling'),
    '#default_value' => $tz_handling,
    '#options' => date_timezone_handling_options(),
    '#description' => $description,
    '#disabled' => $has_data,
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'date') . '/date_admin.js',
      ),
    ),
  );

  // Force this value to hidden because we don't want to allow it to be changed
  // right now, but allow it to be a variable if needed.
  $form['timezone_db'] = array(
    '#type' => 'hidden',
    '#value' => date_get_timezone_db($tz_handling),
  );
  $form['cache_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Cache dates'),
    '#description' => t('Date objects can be created and cached as date fields are loaded rather than when they are displayed to improve performance.'),
    '#default_value' => !empty($settings['cache_enabled']),
    '#weight' => 10,
  );
  $form['cache_count'] = array(
    '#type' => 'textfield',
    '#title' => t('Maximum dates per field'),
    '#default_value' => isset($settings['cache_count']) ? $settings['cache_count'] : 4,
    '#description' => t("If set to '0', all date values on every entity will be cached. Note that caching every date on fields that may have a large number of multiple or repeating values may create a significant performance penalty when the cache is cleared. The suggested setting for multiple value and repeating fields is no more than 4 values per field."),
    '#size' => 3,
    '#weight' => 11,
    '#states' => array(
      'visible' => array(
        'input[name="field[settings][cache_enabled]"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $context = array(
    'field' => $field,
    'instance' => $instance,
    'has_data' => $has_data,
  );
  drupal_alter('date_field_settings_form', $form, $context);
  return $form;
}