Index: cckdatetest.profile
===================================================================
RCS file: /cvs/drupal-contrib/contributions/profiles/cckdatetest/cckdatetest.profile,v
retrieving revision 1.4
diff -u -r1.4 cckdatetest.profile
--- cckdatetest.profile	25 Nov 2008 00:12:41 -0000	1.4
+++ cckdatetest.profile	28 Nov 2008 22:28:04 -0000
@@ -1,10 +1,15 @@
 <?php
-// $Id: cckdatetest.profile,v 1.4 2008/11/25 00:12:41 dww Exp $
+// $Id: cckdatetest.profile,v 1.3 2008/11/23 21:42:11 dww Exp $
 
 /**
  * Should the profile enable and configure calendar (and views)?
  */
-define('CCKDATETEST_ENABLE_CALENDAR', TRUE);
+define('CCKDATETEST_ENABLE_CALENDAR', FALSE);
+
+/**
+ * Should the profile show the devel query log?
+ */
+define('CCKDATETEST_SHOW_QUERIES', TRUE);
 
 /**
  * Password for all of the auto-generated users.
@@ -56,7 +61,7 @@
     $modules[] = 'date_php4';
   }
   if (CCKDATETEST_ENABLE_CALENDAR) {
-    $modules += array('views', 'views_ui', 'calendar', 'calendar_ical');
+    $modules = array_merge($modules, array('date_popup', 'date_repeat', 'views', 'views_ui', 'calendar', 'calendar_ical'));
   }
   return $modules;
 }
@@ -126,36 +131,140 @@
 }
 
 /** 
- * Load all the content type definitions in content_types/*.inc.
+ * Create all possible combinations of date types, widget types, 
+ * and timezone handling.
  */
 function cckdatetest_create_content_types() {
-  $path = drupal_get_path('profile', 'cckdatetest') .'/content_types';
+  
+  // Comment out values you don't want to create.
+  $field_types = array(
+    'date', 
+    'datestamp', 
+    'datetime',
+    );
+  $tz_handlings = array(
+    'date', 
+    'site', 
+    'user', 
+    'none', 
+    'utc',
+    );
+  $widget_types = array(
+    //'date_text', 
+    'date_select', 
+    //'date_popup', 
+    //'date_text_repeat', 
+    //'date_select_repeat', 
+    //'date_popup_repeat',
+    );
+    
+  // Set overrides that apply to all date fields.  
+  $overrides = array(
+    // Make date fields multiple value so multiple values can be tested.
+    'multiple' => 1, 
+    // Move the date above the node body.
+    'weight' => -1,
+    // Set a display format that will show complete date information, 
+    // including the timezone, to help test that values are correct.
+    'output_format_date' => variable_get('date_format_long',  'l, F j, Y - H:i') .' e',
+    );
+  
   $calendar_options = array();
-  if ($handle = opendir($path)) {
-    while ($file = readdir($handle)) {
-      if (preg_match('@(.*)\.inc$@', $file)) {
-        $file_path = $path .'/'. $file;
-        install_content_copy_import_from_file($file_path);
-
-        // Add default calendars for all the date content types if desired.
-        if (CCKDATETEST_ENABLE_CALENDAR && substr($file, 0, 4) == 'date') {
-          $type_name = str_replace('.inc', '', $file);
-          $field_name = 'field_'. $type_name;
-          $option = array(
-            'name' => 'calendar_'. $field_name,
-            'description' => 'An event calendar for the '. $field_name .' field.',
-            'path' => 'calendar-'. str_replace('_', '-', $field_name),
-            'types' => array($type_name),
-            'date_fields' => array($field_name),
-          );
-          $calendar_options[] = $option;
-        }
+  $fields = array();
+  $calendar_tz_fields = array();
+  $calendar_tz_types = array();
+  foreach ($field_types as $field_type) {
+    foreach ($tz_handlings as $tz_handling) {
+      foreach ($widget_types as $widget_type) {
+        $field = cckdatetest_create_type($field_type, $widget_type, $tz_handling, $overrides);
+        $fields[] = $field;
+        $calendar_tz_fields[$tz_handling][] = $field['field_name'];
+        $calendar_tz_types[$tz_handling][] = $field['type_name'];
       }
     }
+  }
+  // Add default calendars for each type of timezone handling.
+  if (CCKDATETEST_ENABLE_CALENDAR) {
+    foreach ($calendar_tz_types as $tz_handling => $tz_types) {
+      $option = array(
+        'name' => 'calendar_'. $tz_handling,
+        'description' => 'An event calendar for all fields using '. $tz_handling .' timezone handling.',
+        'path' => 'calendar-'. $tz_handling,
+        'types' => $calendar_tz_types[$tz_handing],
+        'date_fields' => $calendar_tz_fields[$tz_handling],
+      );
+      $calendar_options[] = $option;
+    }
     if (!empty($calendar_options)) {
       variable_set('calendar_default_view_options', $calendar_options);
     }
   }
+  // For debugging, return the field arrays that were created.
+  return $fields;
+}
+
+function cckdatetest_create_type($field_type, $widget_type, $tz_handling, $overrides = array()) {
+  
+  module_load_include('inc', 'node', 'content_types');
+  module_load_include('inc', 'content', 'includes/content.admin');
+  module_load_include('inc', 'content', 'includes/content.crud');
+  module_load_include('inc', 'date', 'date_admin');
+  
+  // Set overrides for this specific field instance.
+  
+  // Customize the field name and label to match the settings.
+  $overrides['field_name'] = 'field_'. $field_type .'_'. $tz_handling .'_'. $widget_type;
+  $overrides['type_name'] = $field_type .'_'. $tz_handling.'_'. $widget_type;
+  $overrides['widget']['label'] = ucwords($field_type .' '. $tz_handling .' - '. $widget_type);
+  
+  // Get field default values for this combination of field and widget type,
+  // using a helper function in the Date module.
+  $field = date_field_default_values($field_type, $widget_type, $tz_handling, $overrides);
+  
+  // Create the content type.
+  $values  = array (
+    'name' => ucwords($field_type .'_'. $tz_handling .' '. $widget_type),
+    'type' => $field['type_name'],
+    'description' => 'Nodes with CCK field type: '. $field_type .' and widget type: '. $widget_type .' configured with TZ handling: '.$tz_handling,
+    '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' => $field['type_name'],
+    'orig_type' => '',
+    'module' => 'node',
+    'custom' => '1',
+    'modified' => '1',
+    'locked' => '0',
+    'signup_node_default_state' => 'enabled_on',
+  );
+
+  $type = (object) $values;
+  
+  // Prevent a warning in node/content_types.inc
+  $type->has_title = TRUE;
+  $form_state = array('values' => $values);
+  
+  // There is no API for creating node types, so do it using FAPI.
+  // We can't use drupal_execute() when creating more than 
+  // one node type form in a session because of static variables,
+  // so we call node_type_form_submit() directly.
+  $form = node_type_form($form_state, $type);
+  $form['#programmed'] = TRUE;
+  node_type_form_submit($form, $form_state) ;
+
+  content_clear_type_cache();
+  content_field_instance_create($field);
+  
+  return $field;      
 }
 
 /**
@@ -314,6 +423,15 @@
   // Make sure the switch user block is big enough for all the
   // auto-generated users on the site.
   variable_set('devel_switch_user_list_size', 15);
+  
+  // Turn on query display for devel module.
+  if (CCKDATETEST_SHOW_QUERIES) {
+    variable_set('dev_query', 1);
+    variable_set('devel_query_display', 1);
+    variable_set('devel_redirect_page', 1);
+    variable_set('dev_timer', 1);
+    variable_set('dev_mem', 1);  
+  }
 }
 
 function cckdatetest_configure_signup() {

