system_add_date_format_type_form
- Versions
- 7
system_add_date_format_type_form($form, &$form_state)
Add new date type.
Related topics
Code
modules/system/system.admin.inc, line 1939
<?php
function system_add_date_format_type_form($form, &$form_state) {
$form['date_type'] = array(
'#title' => t('Date type'),
'#type' => 'textfield',
'#required' => TRUE,
'#field_suffix' => ' <small id="edit-date-type-suffix"> </small>',
);
$js_settings = array(
'type' => 'setting',
'data' => array(
'machineReadableValue' => array(
'date-type' => array(
'text' => t('Machine name'),
'target' => 'machine-name',
'searchPattern' => '[^a-z0-9]+',
'replaceToken' => '_',
),
),
),
);
$form['machine_name'] = array(
'#title' => t('Machine readable name'),
'#description' => t('The unique machine readable name for this date type, can only contain lowercase letters, numbers and underscores.'),
'#type' => 'textfield',
'#required' => TRUE,
'#attached' => array(
'js' => array(drupal_get_path('module', 'system') . '/system.js', $js_settings),
),
);
// 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['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;
}
?>Login or register to post comments 