function system_configure_date_formats_form

Allow users to add additional date formats.

Parameters

string $date_format_id: (optional) When present, provides the machine name of the date format that is being modified. Defaults to an empty string.

1 string reference to 'system_configure_date_formats_form'
system_menu in drupal/core/modules/system/system.module
Implements hook_menu().

File

drupal/core/modules/system/system.admin.inc, line 2596
Admin page callbacks for the system module.

Code

function system_configure_date_formats_form($form, &$form_state, $date_format_id = '') {
  $formats = system_get_date_formats();
  $format_info = config('system.date')
    ->get('formats.' . $date_format_id);
  $patterns = $format_info['pattern'];
  $date = new DrupalDateTime();
  $pattern = $date
    ->canUseIntl() ? $patterns[DrupalDateTime::INTL] : $patterns[DrupalDateTime::PHP];
  $form['date_format_name'] = array(
    '#type' => 'textfield',
    '#title' => 'Name',
    '#maxlength' => 100,
    '#description' => t('Name of the date format'),
    '#default_value' => empty($format_info['name']) ? '' : $format_info['name'],
  );
  $now = !empty($date_format_id) ? t('Displayed as %date', array(
    '%date' => format_date(REQUEST_TIME, $date_format_id),
  )) : '';
  $form['date_format_id'] = array(
    '#type' => 'machine_name',
    '#title' => t('Machine-readable name'),
    '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
    '#disabled' => !empty($date_format_id),
    '#default_value' => $date_format_id,
    '#machine_name' => array(
      'exists' => 'system_date_format_exists',
      'source' => array(
        'date_format_name',
      ),
    ),
  );
  if (class_exists('intlDateFormatter')) {
    $description = t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array(
      '@url' => 'http://userguide.icu-project.org/formatparse/datetime',
    ));
  }
  else {
    $description = t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array(
      '@url' => 'http://php.net/manual/function.date.php',
    ));
  }
  $form['date_format_pattern'] = array(
    '#type' => 'textfield',
    '#title' => t('Format string'),
    '#maxlength' => 100,
    '#description' => $description,
    '#default_value' => empty($pattern) ? '' : $pattern,
    '#field_suffix' => ' <small id="edit-date-format-suffix">' . $now . '</small>',
    '#ajax' => array(
      'callback' => 'system_date_time_lookup',
      'event' => 'keyup',
      'progress' => array(
        'type' => 'throbber',
        'message' => NULL,
      ),
    ),
    '#required' => TRUE,
  );
  $languages = language_list();
  $options = array();
  foreach ($languages as $langcode => $data) {
    $options[$langcode] = $data->name;
  }
  if (!empty($options)) {
    $form['date_langcode'] = array(
      '#title' => t('Select localizations'),
      '#type' => 'select',
      '#options' => $options,
      '#multiple' => TRUE,
      '#default_value' => empty($format_info['locales']) ? '' : $format_info['locales'],
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['update'] = array(
    '#type' => 'submit',
    '#value' => !empty($date_format_id) ? t('Save format') : t('Add format'),
  );
  $form['#validate'][] = 'system_date_formats_form_validate';
  $form['#submit'][] = 'system_date_formats_form_submit';
  return $form;
}