? includes/features.fieldgroup.inc
Index: includes/features.content.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/features/includes/features.content.inc,v
retrieving revision 1.1.2.9
diff -u -p -r1.1.2.9 features.content.inc
--- includes/features.content.inc	26 Aug 2009 05:13:41 -0000	1.1.2.9
+++ includes/features.content.inc	15 Sep 2009 19:25:48 -0000
@@ -47,39 +47,52 @@ function content_features_export($data, 
       $split = explode('-', $instance);
       $type_name = $split[0];
       $field_name = $split[1];
-      $field = content_fields($field_name, $type_name);
-
-      if ($field) {
-        // Add field item instance for later export.
-        $export['features']['content'][$instance] = $instance;
-
-        // Add module which provides field.
-        $export['dependencies'][$field['module']] = $field['module'];
-
-        // Add module which provides field widget.
-        $export['dependencies'][$field['widget']['module']] = $field['widget']['module'];
-
-        // Add modules which provide display.
-        foreach (array('teaser', 'full') as $display) {
-          $formatter = _content_get_formatter($field['display_settings'][$display]['format'], $field['type']);
-          $export['dependencies'][$formatter['module']] = $formatter['module'];
-
-          // TODO make this logic more generic, for now though we just handle
-          // the imagecache presets.
-          if ($formatter['module'] == 'imagecache') {
-            $format = $field['display_settings'][$display]['format'];
-
-            $parts = explode('_', $format);
-            $style = array_pop($parts);
-            $presetname = implode('_', $parts);
+      // Set up a fieldgroup for exporting.
+      if (module_exists('fieldgroup') && substr($field_name, 0, 5) == 'group') {
+        $fieldgroups = fieldgroup_groups($type_name);
+        if (isset($fieldgroups[$field_name])) {
+          $export['dependencies']['fieldgroup'] = 'fieldgroup';
+          $export['features']['content'][$instance] = $instance;
+          // Handle multigroup dependency, CCK 6.3.
+          if ($fieldgroups[$field_name]['group_type'] == 'multigroup') {
+            $export['dependencies']['content_multigroup'] = 'content_multigroup';
+          }
+        }
+      }
+      // Any CCK field that isn't a fieldgroup.
+      else {
+        $field = content_fields($field_name, $type_name);
+        if ($field) {
+          // Add field item instance for later export.
+          $export['features']['content'][$instance] = $instance;
+
+          // Add module which provides field.
+          $export['dependencies'][$field['module']] = $field['module'];
+
+          // Add module which provides field widget.
+          $export['dependencies'][$field['widget']['module']] = $field['widget']['module'];
+
+          // Add modules which provide display.
+          foreach (array('teaser', 'full') as $display) {
+            $formatter = _content_get_formatter($field['display_settings'][$display]['format'], $field['type']);
+            $export['dependencies'][$formatter['module']] = $formatter['module'];
+
+            // TODO make this logic more generic, for now though we just handle
+            // the imagecache presets.
+            if ($formatter['module'] == 'imagecache') {
+              $format = $field['display_settings'][$display]['format'];
+
+              $parts = explode('_', $format);
+              $style = array_pop($parts);
+              $presetname = implode('_', $parts);
 
-            $pipe[$formatter['module']][] = $presetname;
+              $pipe[$formatter['module']][] = $presetname;
+            }
           }
         }
       }
     }
   }
-
   return $pipe;
 }
 
@@ -90,24 +103,47 @@ function content_features_export_render(
   $translatables = $code = array();
 
   $code[] = '  $fields = array();';
+  // Fieldgroups should have their own array so we can export them to
+  // code in any order, but handle them before fields on import.
+  if (module_exists('fieldgroup')) {
+    $code[] = '  $fields[\'groups\'] = array();';
+  }
   $code[] = '';
   foreach ($data as $instance) {
     $instance = explode('-', $instance);
     $type_name = $instance[0];
     $field_name = $instance[1];
 
-    $field = content_fields($field_name, $type_name);
-    unset($field['columns']);
-    unset($field['locked']);
-    unset($field['db_storage']);
-
-    $code[] = '  // Exported field: '. $field_name;
-    $code[] = '  $fields[] = '. features_var_export($field, '  ') .';';
-    $code[] = '';
-
-    // Add any labels to translatables array.
-    if (!empty($field['widget']['label'])) {
-      $translatables[] = $field['widget']['label'];
+    // If this field is really a group.
+    if (module_exists('fieldgroup') && substr($field_name, 0, 5) == 'group') {
+      $fieldgroups = fieldgroup_groups($type_name);
+      if (isset($fieldgroups[$field_name])) {
+        $fieldgroup = $fieldgroups[$field_name];
+        $fieldgroup['fields'] = array_keys($fieldgroup['fields']);
+        $code[] = '  // Exported fieldset: ' . $field_name;
+        $code[] = '  $fields[\'groups\'][] = ' . features_var_export($fieldgroup, '  ') . ';';
+        $code[] = '';
+        // Add label to translatables.
+        if (!empty($fieldgroup['label'])) {
+          $translatables[] = $fieldgroup['label'];
+        }
+      }
+    }
+    // Any CCK field.
+    else {
+      $field = content_fields($field_name, $type_name);
+      unset($field['columns']);
+      unset($field['locked']);
+      unset($field['db_storage']);
+
+      $code[] = '  // Exported field: '. $field_name;
+      $code[] = '  $fields[] = '. features_var_export($field, '  ') .';';
+      $code[] = '';
+
+      // Add any labels to translatables array.
+      if (!empty($field['widget']['label'])) {
+        $translatables[] = $field['widget']['label'];
+      }
     }
   }
   if (!empty($translatables)) {
@@ -157,6 +193,19 @@ function content_features_rebuild() {
   content_clear_type_cache(TRUE);
 
   $fields = module_invoke_all('content_default_fields');
+  $fieldgroup_field_map = array();
+  if (!empty($fields['groups'])) {
+    // Create fieldgroups if they don't already exist.
+    foreach ($fields['groups'] as $group) {
+      fieldgroup_save_group($group['type_name'], $group);
+      foreach ($group['fields'] as $field) {
+        $fieldgroup_field_map[$field] = $group['group_name'];
+      }
+    }
+    // Reset the static variable in fieldgroup_groups() with new data.
+    fieldgroup_groups('', FALSE, TRUE);
+    unset($fields['groups']);
+  }
   foreach ($fields as $field) {
     $conflicts = array();
     $existing_field = content_fields($field['field_name']);
@@ -188,5 +237,13 @@ function content_features_rebuild() {
         variable_set('menu_rebuild_needed', TRUE);
       }
     }
+    // Update the group of this field.
+    if (module_exists('fieldgroup')) {
+      // Put this field in its group, if needed.
+      if (isset($fieldgroup_field_map[$field['field_name']])) {
+        $field['group'] = $fieldgroup_field_map[$field['field_name']];
+      }
+      fieldgroup_update_fields($field);
+    }
   }
-}
+}
\ No newline at end of file
Index: includes/features.node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/features/includes/features.node.inc,v
retrieving revision 1.1.2.10
diff -u -p -r1.1.2.10 features.node.inc
--- includes/features.node.inc	13 Sep 2009 23:20:28 -0000	1.1.2.10
+++ includes/features.node.inc	15 Sep 2009 19:25:48 -0000
@@ -54,8 +54,22 @@ function node_features_export($data, &$e
 
       // Create a pipe for CCK fields
       if (module_exists('content')) {
+        // Find fieldgroups.
+        if (module_exists('fieldgroup')) {
+          $groups = fieldgroup_groups($type);
+          if (!empty($groups)) {
+            $pipe['content'] = array();
+            foreach ($groups as $key => $group) {
+              $pipe['content'][] = "{$type}-{$group['group_name']}";
+            }
+          }
+        }
+        // Find fields.
         $content_info = content_types($type);
         if (!empty($content_info['fields'])) {
+          if (!isset($pipe['content'])) {
+            $pipe['content'] = array();
+          }
           foreach ($content_info['fields'] as $key => $field) {
             $pipe['content'][] = "{$type}-{$field['field_name']}";
           }
