system_configure_date_formats_form

Versions
7
system_configure_date_formats_form($form, &$form_state, $dfid = 0)

Allow users to add additional date formats.

Code

modules/system/system.admin.inc, line 2668

<?php
function system_configure_date_formats_form($form, &$form_state, $dfid = 0) {
  $js_settings = array(
    'type' => 'setting',
    'data' => array(
      'dateTime' => array(
        'date-format' => array(
          'text' => t('Displayed as'),
          'lookup' => url('admin/config/regional/date-time/formats/lookup'),
        ),
      ),
    ),
  );

  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'),
    '#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),
    ),
  );

  $form['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;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.