FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* A form to change the type of date used in date fields.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form constructor for the date type change form.
|
||||
*
|
||||
* @see date_tools_change_type_form_validate()
|
||||
* @see date_tools_change_type_form_submit()
|
||||
*/
|
||||
function date_tools_change_type_form() {
|
||||
$form = array();
|
||||
// This is broken, still needs to be adjusted for the D6->D7 changes.
|
||||
drupal_set_message(t('This operation does not yet work for the Drupal 7 version.'), 'error');
|
||||
return $form;
|
||||
$fields = content_fields();
|
||||
$date_options = array();
|
||||
$type_options = array();
|
||||
|
||||
$labels = array();
|
||||
foreach (date_field_info() as $type => $info) {
|
||||
$type_options[$type] = $info['label'] . ': ' . $info['description'];
|
||||
$labels[$type] = $info['label'];
|
||||
}
|
||||
// Get the available date fields.
|
||||
foreach ($fields as $field_name => $field) {
|
||||
if ($field['type'] == 'date' || $field['type'] == 'datestamp' || $field['type'] == 'datetime') {
|
||||
$date_options[$labels[$field['type']]][$field_name] = t('Field @label (@field_name)', array('@label' => $field['widget']['label'], '@field_name' => $field_name, '@type' => $labels[$field['type']]));
|
||||
}
|
||||
}
|
||||
if (sizeof($date_options) < 1) {
|
||||
drupal_set_message(t('There are no date fields in this database.'));
|
||||
return $form;
|
||||
}
|
||||
$form['date_field'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => $date_options,
|
||||
'#title' => t('Date field'),
|
||||
'#default_value' => '',
|
||||
'#description' => t('The date field which whose type should be changed.'),
|
||||
);
|
||||
$form['type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#options' => $type_options,
|
||||
'#default_value' => '',
|
||||
'#required' => TRUE,
|
||||
'#description' => t('The type of date to change the field to.'),
|
||||
'#prefix' => '<strong>' . t('New type:') . '</strong>',
|
||||
);
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => t('Change'));
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form validation handler for date_tools_change_type_form().
|
||||
*
|
||||
* @see date_tools_change_type_form_submit()
|
||||
*/
|
||||
function date_tools_change_type_form_validate($form, &$form_state) {
|
||||
$field_name = $form_state['values']['date_field'];
|
||||
$new_type = $form_state['values']['type'];
|
||||
$field = content_fields($field_name);
|
||||
$old_type = $field['type'];
|
||||
if ($new_type == $old_type) {
|
||||
form_set_error('type', t('The current type is the same as the chosen type. There is nothing to change.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission handler for date_tools_change_type_form().
|
||||
*
|
||||
* @see date_tools_change_type_form_validate()
|
||||
*/
|
||||
function date_tools_change_type_form_submit($form, &$form_state) {
|
||||
$field_name = $form_state['values']['date_field'];
|
||||
$new_type = $form_state['values']['type'];
|
||||
$field = content_fields($field_name);
|
||||
$old_type = $field['type'];
|
||||
if ($new_type == $old_type) {
|
||||
return;
|
||||
}
|
||||
$db_info = content_database_info($field);
|
||||
$table = $db_info['table'];
|
||||
$columns = $db_info['columns'];
|
||||
$labels = array();
|
||||
foreach (date_field_info() as $type => $info) {
|
||||
$labels[$type] = $info['label'];
|
||||
}
|
||||
|
||||
// Is there any data in this field? If not, we can
|
||||
// skip some steps.
|
||||
$has_data = db_query("SELECT COUNT(*) FROM {" . $table . "}")->fetchField();
|
||||
|
||||
// Create a backup copy of the original values.
|
||||
// The values are going to get corrupted when we
|
||||
// change the column type.
|
||||
if ($has_data) {
|
||||
$temp_table = $table . '_temp';
|
||||
db_query("CREATE TABLE {" . $temp_table . "} SELECT * FROM {" . $table . "}");
|
||||
}
|
||||
|
||||
// Change the field definition to the new type.
|
||||
$field['type'] = $new_type;
|
||||
require_once './' . drupal_get_path('module', 'content') . '/includes/content.crud.inc';
|
||||
content_field_instance_update($field, FALSE);
|
||||
content_clear_type_cache();
|
||||
|
||||
// If there's no data to update, we're finished.
|
||||
if (!$has_data) {
|
||||
drupal_set_message(t('The field @field_name has been changed from @old_type to @new_type.', array(
|
||||
'@field_name' => $field['widget']['label'], '@old_type' => $labels[$old_type], '@new_type' => $labels[$new_type])));
|
||||
return;
|
||||
}
|
||||
|
||||
// Replace old values with modified values, massaging the original values as
|
||||
// necessary for the new type.
|
||||
require_once './' . drupal_get_path('module', 'date_api') . '/date_api_sql.inc';
|
||||
$date_handler = new date_sql_handler();
|
||||
$date_handler->granularity = $field['granularity'];
|
||||
$date_handler->date_type = $old_type;
|
||||
|
||||
$new_columns = array();
|
||||
$old_columns = array('nid', 'vid');
|
||||
$new_columns[] = $temp_table . '.nid AS nid';
|
||||
$new_columns[] = $temp_table . '.vid AS vid';
|
||||
if ($field->multiple) {
|
||||
$new_columns[] = $temp_table . '.delta AS delta';
|
||||
$old_columns[] = 'delta';
|
||||
}
|
||||
foreach ($columns as $column => $info) {
|
||||
if ($column != 'value' && $column != 'value2') {
|
||||
continue;
|
||||
}
|
||||
$old_columns[] = $info['column'];
|
||||
$db_field = $date_handler->sql_field($temp_table . '.' . $info['column'], 0);
|
||||
switch ($old_type) {
|
||||
case 'date':
|
||||
switch ($new_type) {
|
||||
case 'datestamp':
|
||||
$new_columns[] = $date_handler->sql_format('U', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
case 'datetime':
|
||||
$new_columns[] = $date_handler->sql_format('Y-m-d H:i:s', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'datestamp':
|
||||
switch ($new_type) {
|
||||
case 'date':
|
||||
$new_columns[] = $date_handler->sql_format('Y-m-d/TH:i:s', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
case 'datetime':
|
||||
$new_columns[] = $date_handler->sql_format('Y-m-d H:i:s', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'datetime':
|
||||
switch ($new_type) {
|
||||
case 'date':
|
||||
$new_columns[] = $date_handler->sql_format('Y-m-d/TH:i:s', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
case 'datestamp':
|
||||
$new_columns[] = $date_handler->sql_format('U', $db_field) . ' AS ' . $info['column'];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure database timezone is set to UTC.
|
||||
$date_handler->set_db_timezone();
|
||||
|
||||
// Make the replacement.
|
||||
$sql = 'REPLACE INTO {' . $table . '} (' . implode(', ', $old_columns) . ') ' . ' SELECT ' . implode(', ', $new_columns) . ' FROM {' . $temp_table . '}';
|
||||
db_query($sql);
|
||||
db_query("DROP TABLE {" . $temp_table . "}");
|
||||
|
||||
drupal_set_message(t('The field @field_name has been changed from @old_type to @new_type.', array('@field_name' => $field['widget']['label'], '@old_type' => $labels[$old_type], '@new_type' => $labels[$new_type])));
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = Date Tools
|
||||
description = Tools to import and auto-create dates and calendars.
|
||||
dependencies[] = date
|
||||
package = Date/Time
|
||||
core = 7.x
|
||||
configure = admin/config/date/tools
|
||||
files[] = tests/date_tools.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-08-13
|
||||
version = "7.x-2.6"
|
||||
core = "7.x"
|
||||
project = "date"
|
||||
datestamp = "1344850024"
|
||||
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @todo.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function date_tools_help($section, $arg) {
|
||||
switch ($section) {
|
||||
case 'admin/config/date/tools':
|
||||
return '<p>' . t('<h2>Tools for Dates and Calendars</h2>') . '</p>';
|
||||
|
||||
case 'admin/config/date/tools/change':
|
||||
return '<p>' . t('Change a date field from one type to another. Very experimental, use at your own risk!') . '</p>';
|
||||
|
||||
case 'admin/config/date/tools/date_wizard':
|
||||
|
||||
$output = t("Fill out the following form to auto-create a date content type, with a datetime field and matching pre-configured calendar. If the calendar module is enabled and the option to create a calendar is chosen, a calendar and upcoming events block will be created, an ical feed will be added to the calendar. Nodes created from this new content type will include a link to the calendar, and the calendar will have a link to the 'add new date' form. You can also add new date fields to an existing content type by entering the existing content type name instead of creating a new one.") .
|
||||
'</p><p>' .
|
||||
t('Only a limited set of options are displayed here to make this easy to set up. Once the date has been created you will be able to make other changes to the date settings and add other fields to your new content type on the Manage fields screen. You can also make changes to the calendar on the Views edit page.') .
|
||||
'</p>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function date_tools_permission() {
|
||||
return array(
|
||||
'administer date tools' => array(
|
||||
'title' => t('Administer date tools'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function date_tools_menu() {
|
||||
|
||||
$items = array();
|
||||
$items['admin/config/date/tools'] = array(
|
||||
'title' => 'Date Tools',
|
||||
'description' => 'Date Wizard and other tools to manage and create dates and calendars. ',
|
||||
'access arguments' => array('administer date tools'),
|
||||
'page callback' => 'date_tools_page',
|
||||
);
|
||||
$items['admin/config/date/tools/about'] = array(
|
||||
'title' => 'About',
|
||||
'description' => 'Date Wizard and other tools to manage and create dates and calendars. ',
|
||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||
'weight' => -5,
|
||||
'page callback' => 'date_tools_page',
|
||||
'access arguments' => array('administer date tools'),
|
||||
);
|
||||
$items['admin/config/date/tools/date_wizard'] = array(
|
||||
'title' => 'Date wizard',
|
||||
'description' => 'Easy creation of date content types and calendars. ',
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 1,
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('date_tools_wizard_form'),
|
||||
'access arguments' => array('administer date tools'),
|
||||
'file' => 'date_tools.wizard.inc',
|
||||
);
|
||||
|
||||
/**
|
||||
$items['admin/config/date/tools/change'] = array(
|
||||
'title' => 'Change type',
|
||||
'access arguments' => array('administer date tools'),
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('date_tools_change_type_form'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 3,
|
||||
'file' => 'date_tools.change_type.inc',
|
||||
);
|
||||
*/
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Date Tools page
|
||||
*/
|
||||
function date_tools_page() {
|
||||
$content = '';
|
||||
|
||||
$content .= t('Dates and calendars can be complicated to set up. The !date_wizard makes it easy to create a simple date content type and related calendar. ', array('!date_wizard' => l(t('Date wizard'), 'admin/config/date/tools/date_wizard')));
|
||||
|
||||
|
||||
return $content;
|
||||
}
|
@@ -0,0 +1,392 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The Date Wizard code.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_form() {
|
||||
$form = array();
|
||||
$form['type'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Content type'),
|
||||
);
|
||||
$form['type']['bundle'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => 'date',
|
||||
'#title' => t('Content type name'),
|
||||
'#description' => t('Machine-readable name. Allowed values: (a-z, 0-9, _). If this is not an existing content type, the content type will be created.'),
|
||||
);
|
||||
$form['type']['name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => t('Date'),
|
||||
'#title' => t('Content type label'),
|
||||
'#description' => t('The human-readable name for this content type. Only needed when creating a new content type.'),
|
||||
);
|
||||
$form['type']['type_description'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#default_value' => t('A date content type that is linked to a Views calendar.'),
|
||||
'#title' => t('Content type description'),
|
||||
'#description' => t('A description for the content type. Only needed when creating a new content type.'),
|
||||
);
|
||||
$form['field'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Date field'),
|
||||
);
|
||||
$form['field']['field_name'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => 'date',
|
||||
'#field_prefix' => 'field_',
|
||||
'#title' => t('Date field name'),
|
||||
'#description' => t('Machine-readable name. Allowed values: (a-z, 0-9, _) Must not be an existing field name.'),
|
||||
);
|
||||
$form['field']['label'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => t('Date'),
|
||||
'#title' => t('Date field label'),
|
||||
'#description' => t('The human-readable label for this field.'),
|
||||
);
|
||||
$form['field']['widget_type'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => date_tools_wizard_widget_types(),
|
||||
'#default_value' => 'date_select',
|
||||
'#title' => t('Date widget type'),
|
||||
);
|
||||
$form['field']['repeat'] = array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => 0,
|
||||
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
||||
'#title' => t('Show repeating date options'),
|
||||
'#access' => module_exists('date_repeat_field'),
|
||||
);
|
||||
$form['field']['advanced'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#title' => t('Advanced options'),
|
||||
);
|
||||
$form['field']['advanced']['todate'] = array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => 'optional',
|
||||
'#options' => array('' => t('Never'), 'optional' => t('Optional'), 'required' => t('Required')),
|
||||
'#title' => t('End Date'),
|
||||
'#description' => t("Display a matching second date field as a 'End date'."),
|
||||
);
|
||||
$form['field']['advanced']['field_type'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => date_tools_wizard_field_types(),
|
||||
'#default_value' => 'datetime',
|
||||
'#title' => t('Date field type'),
|
||||
'#description' => t("The recommend type is Datetime, except for historical dates or dates with only year or month granularity. Older or incomplete dates should use the Date type (an ISO date)."),
|
||||
);
|
||||
$form['field']['advanced']['granularity'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => date_granularity_names(),
|
||||
'#default_value' => array('month', 'day', 'year', 'hour', 'minute'),
|
||||
'#title' => t('Granularity'),
|
||||
'#multiple' => TRUE,
|
||||
);
|
||||
$form['field']['advanced']['year_range'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => '-1:+1',
|
||||
'#title' => t('Year range'),
|
||||
'#description' => t("Range of allowed years, oldest to newest. '-1:+1 means oldest date is one year back, newest is one year forward from current year."),
|
||||
);
|
||||
$form['field']['advanced']['tz_handling'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => date_tools_wizard_tz_handling(),
|
||||
'#default_value' => 'site',
|
||||
'#title' => t('Date timezone handling'),
|
||||
'#description' => t("Timezone handling should be set to 'none' for granularity without time elements."),
|
||||
);
|
||||
$form['calendar'] = array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => module_exists('calendar'),
|
||||
'#options' => array(0 => t('No'), 1 => t('Yes')),
|
||||
'#title' => t('Create a calendar for this date field'),
|
||||
'#access' => module_exists('calendar'),
|
||||
);
|
||||
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_form_validate(&$form, &$form_state) {
|
||||
$bundle = $form_state['values']['bundle'];
|
||||
$field_name = 'field_' . $form_state['values']['field_name'];
|
||||
$existing_type = db_query("SELECT type FROM {node_type} WHERE type=:bundle", array(':bundle' => $bundle))->fetchField();
|
||||
$existing_instance = db_query("SELECT field_name FROM {field_config_instance} WHERE field_name=:field_name AND bundle=:bundle AND entity_type=:entity_type", array(':field_name' => $field_name, ':bundle' => $bundle, ':entity_type' => 'node'))->fetchField();
|
||||
if ($existing_type) {
|
||||
drupal_set_message(t('This content type name already exists, adding new field to existing content type.'));
|
||||
}
|
||||
if (!preg_match('!^[a-z0-9_]+$!', $bundle)) {
|
||||
form_set_error('bundle', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
|
||||
}
|
||||
if (!empty($form_state['values']['calendar']) && !empty($form_state['values']['blocks']) && strlen($bundle) > 12) {
|
||||
form_set_error('bundle', t('The content type name must be no more than 12 characters long when using it to create a calendar and blocks.'));
|
||||
}
|
||||
if ($existing_instance) {
|
||||
form_set_error('field_name', t('This field name already exists.'));
|
||||
}
|
||||
if (strlen($field_name) > 32) {
|
||||
form_set_error('field_name', t('The field name must be no more than 26 characters long.'));
|
||||
}
|
||||
if (!date_has_time($form_state['values']['granularity']) && $form_state['values']['tz_handling'] != 'none') {
|
||||
form_set_error('tz_handling', t('Timezone handling must be none for granularity without time.'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_form_submit(&$form, &$form_state) {
|
||||
$view_name = date_tools_wizard_build($form_state['values']);
|
||||
menu_rebuild();
|
||||
if (!empty($form_state['values']['calendar']) && !empty($view_name)) {
|
||||
$form_state['redirect'] = 'admin/structure/views/template/' . $view_name . '/add';
|
||||
}
|
||||
else {
|
||||
$form_state['redirect'] = 'admin/structure/types/manage/' . str_replace('_', '-', $form_state['values']['bundle']) . '/fields';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
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' => date_default_format($widget_type),
|
||||
'text_parts' => array(),
|
||||
'label_position' => 'above',
|
||||
'repeat_collapsed' => 0,
|
||||
),
|
||||
'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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_include() {
|
||||
module_load_include('inc', 'node', 'content_types');
|
||||
module_load_include('inc', 'node', 'node.pages');
|
||||
module_load_include('inc', 'field', 'field.crud');
|
||||
module_load_include('inc', 'date', 'date_admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_field_types() {
|
||||
$field_types = array();
|
||||
foreach (date_field_info() as $name => $info) {
|
||||
$field_types[$name] = $info['label'];
|
||||
}
|
||||
return $field_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_widget_types() {
|
||||
$widget_types = array();
|
||||
foreach (date_field_widget_info() as $name => $info) {
|
||||
if (!strstr($name, '_repeat')) {
|
||||
$widget_types[$name] = $info['label'];
|
||||
}
|
||||
}
|
||||
return $widget_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_tz_handling() {
|
||||
include_once drupal_get_path('module', 'date') . '/date_admin.inc';
|
||||
return date_timezone_handling_options();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function date_tools_wizard_create_content_type($name, $bundle, $description, $type_settings = array()) {
|
||||
|
||||
date_tools_wizard_include();
|
||||
|
||||
// Create the content type.
|
||||
$values = array(
|
||||
'name' => $name,
|
||||
'type' => $bundle,
|
||||
'description' => $description,
|
||||
'title_label' => 'Title',
|
||||
'body_label' => 'Body',
|
||||
'min_word_count' => '0',
|
||||
'help' => '',
|
||||
'node_options' =>
|
||||
array(
|
||||
'status' => 1,
|
||||
'promote' => 1,
|
||||
'sticky' => 0,
|
||||
'revision' => 0,
|
||||
),
|
||||
'language_content_type' => '0',
|
||||
'old_type' => $bundle,
|
||||
'orig_type' => '',
|
||||
'base' => 'node_content',
|
||||
'custom' => '1',
|
||||
'modified' => '1',
|
||||
'locked' => '0',
|
||||
'url_str' => str_replace('_', '-', $bundle),
|
||||
);
|
||||
|
||||
// Allow overrides of these values.
|
||||
foreach ($type_settings as $key => $value) {
|
||||
$values[$key] = $value;
|
||||
}
|
||||
|
||||
node_type_save((object) $values);
|
||||
|
||||
// Add the body field.
|
||||
$trim_length = variable_get('teaser_length', 600);
|
||||
|
||||
$field = field_info_field('body');
|
||||
$instance = array(
|
||||
'field_name' => 'body',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundle,
|
||||
'label' => t('Description'),
|
||||
'widget' => array(
|
||||
'type' => 'text_textarea_with_summary',
|
||||
'settings' => array(
|
||||
'rows' => 20,
|
||||
'summary_rows' => 5,
|
||||
),
|
||||
'weight' => -4,
|
||||
'module' => 'text',
|
||||
),
|
||||
'settings' => array('display_summary' => TRUE),
|
||||
'display' => array(
|
||||
'default' => array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_default',
|
||||
),
|
||||
'teaser' => array(
|
||||
'label' => 'hidden',
|
||||
'type' => 'text_summary_or_trimmed',
|
||||
'trim_length' => $trim_length,
|
||||
),
|
||||
),
|
||||
);
|
||||
field_create_instance($instance);
|
||||
|
||||
}
|
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for Date Tools.
|
||||
*/
|
||||
|
||||
class DateToolsTestCase extends DrupalWebTestCase {
|
||||
protected $privileged_user;
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Date Tools',
|
||||
'description' => 'Test Date Wizard and other Date Tools.',
|
||||
'group' => 'Date',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
public function setUp() {
|
||||
// Load the date_api module.
|
||||
parent::setUp('field', 'field_ui', 'date_api', 'date', 'date_popup', 'date_tools');
|
||||
|
||||
// Create and log in our privileged user.
|
||||
$this->privileged_user = $this->drupalCreateUser(
|
||||
array('administer content types', 'administer nodes', 'bypass node access', 'administer date tools')
|
||||
);
|
||||
$this->drupalLogin($this->privileged_user);
|
||||
|
||||
variable_set('date_format_long', 'D, m/d/Y - H:i');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a date field using the Date Wizard.
|
||||
*/
|
||||
public function testTools() {
|
||||
$form_values = array('label' => 'Test', 'field_type' => 'datetime', 'widget_type' => 'date_select', 'todate' => '');
|
||||
$this->createDateWizard($form_values);
|
||||
$this->dateForm($options = 'select');
|
||||
$this->assertText('Thu, 10/07/2010 - 10:30', 'Found the correct date for the Date Wizard datetime field using the date_select widget.');
|
||||
$this->deleteDateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that date field functions properly.
|
||||
*/
|
||||
function dateForm($options) {
|
||||
$edit = array();
|
||||
$edit['title'] = $this->randomName(8);
|
||||
$edit['body[und][0][value]'] = $this->randomName(16);
|
||||
if ($options == 'select') {
|
||||
$edit['field_test[und][0][value][year]'] = '2010';
|
||||
$edit['field_test[und][0][value][month]'] = '10';
|
||||
$edit['field_test[und][0][value][day]'] = '7';
|
||||
$edit['field_test[und][0][value][hour]'] = '10';
|
||||
$edit['field_test[und][0][value][minute]'] = '30';
|
||||
}
|
||||
elseif ($options == 'text') {
|
||||
$edit['field_test[und][0][value][date]'] = '10/07/2010 - 10:30';
|
||||
}
|
||||
elseif ($options == 'popup') {
|
||||
$edit['field_test[und][0][value][date]'] = '10/07/2010';
|
||||
$edit['field_test[und][0][value][time]'] = '10:30';
|
||||
}
|
||||
$this->drupalPost('node/add/story', $edit, t('Save'));
|
||||
$this->assertText($edit['body[und][0][value]'], 'Test node has been created');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
function deleteDateField() {
|
||||
$this->drupalGet('admin/structure/types/manage/story/fields');
|
||||
$this->clickLink('delete');
|
||||
$this->drupalPost(NULL, NULL, t('Delete'));
|
||||
$this->assertText('The field Test has been deleted from the Story content type.', 'Removed date field.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a date field using the Date Wizard.
|
||||
*/
|
||||
function createDateWizard($edit) {
|
||||
$edit += array(
|
||||
'bundle' => 'story',
|
||||
'name' => 'Story',
|
||||
'type_description' => 'A test content type.',
|
||||
'field_name' => 'test',
|
||||
'label' => 'Test',
|
||||
'widget_type' => 'date_select',
|
||||
'todate' => 'optional',
|
||||
'field_type' => 'date',
|
||||
'granularity[]' => array('year', 'month', 'day', 'hour', 'minute'),
|
||||
'tz_handling' => 'site',
|
||||
'year_range' => '2010:+2',
|
||||
);
|
||||
$this->drupalPost('admin/config/date/tools/date_wizard', $edit, t('Save'));
|
||||
$this->assertText('Your date field Test has been created.', 'Create a date field using the Date Wizard.');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user