From 743bf305075b91cc444788abd63da9b3e26c6317 Mon Sep 17 00:00:00 2001
From: Tom Kirkpatrick <tom@systemseed.com>
Date: Fri, 16 Mar 2012 21:45:32 +0100
Subject: [PATCH] Only affect formflow fieldsets rather than any fieldset

---
 formflow.module |   40 ++++++++++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/formflow.module b/formflow.module
index 4027c9d..9d3d2d7 100644
--- a/formflow.module
+++ b/formflow.module
@@ -111,7 +111,21 @@ function formflow_field_group_format_settings($group){
  * Implements hook_field_attach_form().
  */
 function formflow_field_attach_form($entity_type, $entity, &$form, &$form_state, $langcode){
-  formflow_attach_groups($form, $form_state, (isset($entity->is_new) ? 'add' : 'edit'));
+  if (isset($entity->is_new)) {
+    // Some entities provide an "is_new" property. If that is present, respect
+    // whatever it's set to.
+    $is_new = $entity->is_new;
+  }
+  else {
+    // Otherwise, try to find out if the entity is new by checking its ID. Note
+    // that checking empty() rather than !isset() is important here, to deal
+    // with the case of entities that store "0" as their ID while the final
+    // entity is in the process of being created (user accounts are a good
+    // example of this).
+    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
+    $is_new = empty($id);
+  }
+  formflow_attach_groups($form, $form_state, ($is_new ? 'add' : 'edit'));
 }
 
 /**
@@ -521,15 +535,28 @@ function formflow_menu_cache_clear(){
  * @param String $view_mode The mode for the build.
  */
 function formflow_attach_groups(&$form, &$form_state, $display_mode){
-  // If there are no ghroups defined, do nothing
-  if(!isset($form['#groups'])){return;}
+  // If there are no groups defined, do nothing
+  if(!isset($form['#groups'])){
+    return;
+  }
+  // Build up a list of formfield groups.
+  $formflow_groups = array();
+  foreach($form['#groups'] as $group_name => $group) {
+    if ($group->format_type == 'formflow') {
+      $formflow_groups[] = $group_name;
+    }
+  }
+  // If there are no formfield groups, do nothing.
+  if (empty($formflow_groups)) {
+    return;
+  }
   $form['#display_mode'] = $display_mode;
   ctools_add_css('wizard');
   // Attach the fieldgroup CSS
   $form['#attached']['css'] = array(
     drupal_get_path('module', 'formflow') . '/css/formflow.css'
   );
-  // If there's no current step, default tot he first one
+  // If there's no current step, default to the first one
   if(!isset($form_state['current_group'])){
     $form_state['current_group'] = @array_shift(array_keys($form['#groups']));
   }
@@ -541,7 +568,8 @@ function formflow_attach_groups(&$form, &$form_state, $display_mode){
     '#weight' => -1000,
     '#formflow' => true
   );
-  foreach($form['#groups'] as $group){
+
+  foreach($form['#groups'] as $group) {
     if(empty($group->format_settings['instance_settings']['display_mode']) || $group->format_settings['instance_settings']['display_mode'] == $display_mode){
       if($group->group_name == $form['#current_group']){
         $class = 'wizard-trail-current';
@@ -647,7 +675,7 @@ function formflow_field_group_navigate($op, $form, &$form_state){
  * @param $form The form object itself.
  */
 function formflow_field_group_pre_render(&$element, $group, &$form){
-  if(empty($group->format_settings['instance_settings']['display_mode']) || $group->format_settings['instance_settings']['display_mode'] == $form['#display_mode']){
+  if(isset($form['#display_mode']) && (empty($group->format_settings['instance_settings']['display_mode']) || $group->format_settings['instance_settings']['display_mode'] == $form['#display_mode'])){
     $id = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $form['#display_mode'] . '_' . $group->group_name;
     // Prepare extra classes.
     $classes = array(
-- 
1.7.4.4

