function date_tools_wizard_build in Date 8
Same name and namespace in other branches
- 6.2 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
- 7.3 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
- 7 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
- 7.2 date_tools/date_tools.wizard.inc \date_tools_wizard_build()
@todo.
1 call to date_tools_wizard_build()
- date_tools_wizard_form_submit in date_tools/
date_tools.wizard.inc - @todo.
File
- date_tools/
date_tools.wizard.inc, line 168 - The Date Wizard code.
Code
function date_tools_wizard_build($form_values) {
extract($form_values);
$field_name = 'field_' . $field_name;
$base_table = 'node';
// Create a node type if it doesn't already exist.
// This makes it possible to add additional date fields to
// an existing type.
$types = node_type_get_names();
$type_settings = array();
if (!array_key_exists($bundle, $types)) {
date_tools_wizard_create_content_type($name, $bundle, $type_description, $type_settings);
drupal_set_message(t('Your content type @name has been created.', array(
'@name' => $name,
)));
}
else {
$types = node_type_get_types();
$type = $types[$bundle];
if (!empty($type_settings)) {
foreach ($type_settings as $key => $setting) {
$type->{$key} = $setting;
}
node_type_save($type);
}
$name = $type->name;
}
$field = array(
'field_name' => $field_name,
'type' => $field_type,
'cardinality' => $repeat ? FIELD_CARDINALITY_UNLIMITED : 1,
'settings' => array(
'granularity' => $granularity,
'tz_handling' => $tz_handling,
'timezone_db' => date_get_timezone_db($tz_handling),
'repeat' => $repeat,
'todate' => !empty($todate) ? $todate : 'optional',
),
);
$instance = array(
'entity_type' => 'node',
'field_name' => $field_name,
'label' => $label,
'bundle' => $bundle,
// Move the date right below the title.
'weight' => -4,
'widget' => array(
'type' => $widget_type,
// Increment for minutes and seconds, can be 1, 5, 10, 15, or 30.
'settings' => array(
'increment' => 15,
// The number of years to go back and forward in drop-down year
// selectors.
'year_range' => !empty($year_range) ? $year_range : '-0:+1',
'input_format' => variable_get('date_format_html_date', 'Y-m-d') . ' ' . variable_get('date_format_html_time', 'H:i:s'),
'text_parts' => array(),
'label_position' => 'above',
),
'weight' => -4,
),
'settings' => array(
'default_value' => 'now',
'default_value2' => 'blank',
),
);
$instance['display'] = array(
'default' => array(
'label' => 'above',
'type' => 'date_default',
'settings' => array(
'format_type' => 'long',
'show_repeat_rule' => 'show',
'multiple_number' => '',
'multiple_from' => '',
'multiple_to' => '',
'fromto' => 'both',
),
'module' => 'date',
'weight' => 0,
),
'teaser' => array(
'label' => 'above',
'type' => 'date_default',
'weight' => 0,
'settings' => array(
'format_type' => 'long',
'show_repeat_rule' => 'show',
'multiple_number' => '',
'multiple_from' => '',
'multiple_to' => '',
'fromto' => 'both',
),
'module' => 'date',
),
);
$field = field_create_field($field);
$instance = field_create_instance($instance);
$view_name = 'calendar_node_' . $field_name;
field_info_cache_clear(TRUE);
field_cache_clear(TRUE);
drupal_set_message(t('Your date field @name has been created.', array(
'@name' => $label,
)));
return $view_name;
}