You are here

function system_configure_date_formats_form in Drupal 7

Allow users to add additional date formats.

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

File

modules/system/system.admin.inc, line 2897
Admin page callbacks for the system module.

Code

function system_configure_date_formats_form($form, &$form_state, $dfid = 0) {
  $ajax_path = 'admin/config/regional/date-time/formats/lookup';
  $js_settings = array(
    'type' => 'setting',
    'data' => array(
      'dateTime' => array(
        'date-format' => array(
          'text' => t('Displayed as'),
          'lookup' => url($ajax_path, array(
            'query' => array(
              'token' => drupal_get_token($ajax_path),
            ),
          )),
        ),
      ),
    ),
  );
  if ($dfid) {
    $form['dfid'] = array(
      '#type' => 'value',
      '#value' => $dfid,
    );
    $format = system_get_date_format($dfid);
  }
  $now = $dfid ? t('Displayed as %date', array(
    '%date' => format_date(REQUEST_TIME, 'custom', $format->format),
  )) : '';
  $form['date_format'] = array(
    '#type' => 'textfield',
    '#title' => t('Format string'),
    '#maxlength' => 100,
    '#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',
    )),
    '#default_value' => $dfid ? $format->format : '',
    '#field_suffix' => ' <small id="edit-date-format-suffix">' . $now . '</small>',
    '#attached' => array(
      'js' => array(
        drupal_get_path('module', 'system') . '/system.js',
        $js_settings,
      ),
    ),
    '#required' => TRUE,
  );
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['update'] = array(
    '#type' => 'submit',
    '#value' => $dfid ? t('Save format') : t('Add format'),
  );
  $form['#validate'][] = 'system_add_date_formats_form_validate';
  $form['#submit'][] = 'system_add_date_formats_form_submit';
  return $form;
}