function system_add_date_format_type_form

system_add_date_format_type_form($form, &$form_state)

Add new date type.

Related topics

File

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

Code

function system_add_date_format_type_form($form, &$form_state) {
  $form['date_type'] = array(
    '#title' => t('Date type'),
    '#type' => 'textfield',
    '#required' => TRUE,
  );
  $form['machine_name'] = array(
    '#type' => 'machine_name',
    '#machine_name' => array(
      'exists' => 'system_get_date_types',
      'source' => array('date_type'),
    ),
  );

  // Get list of all available date formats.
  $formats = array();
  drupal_static_reset('system_get_date_formats');
  $date_formats = system_get_date_formats(); // Call this to rebuild the list, and to have default list.
  foreach ($date_formats as $type => $format_info) {
    $formats = array_merge($formats, $format_info);
  }
  $custom_formats = system_get_date_formats('custom');
  if (!empty($custom_formats)) {
    $formats = array_merge($formats, $custom_formats);
  }
  $choices = array();
  foreach ($formats as $f => $format) {
    $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
  }
  // Show date format select list.
  $form['date_format'] = array(
    '#type' => 'select',
    '#title' => t('Date format'),
    '#attributes' => array('class' => array('date-format')),
    '#options' => $choices,
    '#required' => TRUE,
  );

  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add date type'),
  );

  $form['#validate'][] = 'system_add_date_format_type_form_validate';
  $form['#submit'][] = 'system_add_date_format_type_form_submit';

  return $form;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!system!system.admin.inc/function/system_add_date_format_type_form/7.x