function data_ui_date_form in Data 7
Form builder for field date configuration.
1 string reference to 'data_ui_date_form'
- data_ui_menu in data_ui/
data_ui.module - Implements hook_menu().
File
- data_ui/
data_ui.admin.inc, line 820 - Admin UI functions.
Code
function data_ui_date_form($form, &$form_state, $table) {
$table = data_get_table($table);
drupal_set_title($table
->get('title'));
$schema = $table
->get('table_schema');
$meta = $table
->get('meta');
$form = array();
// Keep table.
$form['#table'] = $table;
// Create a row of settings per field.
$form['fields'] = array(
'#tree' => TRUE,
);
if (isset($schema['fields'])) {
foreach ($schema['fields'] as $field_name => $field) {
$field_meta_date = isset($meta['fields'][$field_name]['date']) ? $meta['fields'][$field_name]['date'] : array();
$form['fields'][$field_name] = array();
$form['fields'][$field_name]['name'] = array(
'#markup' => check_plain($field_name),
);
$sql_type_options = array(
'' => t('Not a date field'),
DATE_DATETIME => t("Datetime: 'Y-m-d H:i:s'"),
DATE_ISO => t("ISO date: 'Y-m-dTH:i:s'"),
DATE_UNIX => t('Unix timestamp'),
);
$form['fields'][$field_name]['sql_type'] = array(
'#type' => 'select',
'#options' => $sql_type_options,
'#default_value' => isset($field_meta_date['sql_type']) ? $field_meta_date['sql_type'] : '',
);
$granularity_options = array(
'' => t('None'),
) + drupal_map_assoc(array(
'year',
'month',
'day',
'hour',
'minute',
'second',
));
$form['fields'][$field_name]['granularity'] = array(
'#type' => 'select',
'#options' => $granularity_options,
'#default_value' => isset($field_meta_date['granularity']) ? $field_meta_date['granularity'] : '',
'#states' => array(
'disabled' => array(
':input[name="fields[' . $field_name . '][sql_type]"]' => array(
'value' => '',
),
),
),
);
}
}
$form['#header'] = array(
t('Name'),
t('Date type'),
t('Granularity'),
);
$form['#theme'] = 'data_ui_field_config_form';
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}