From ce2b7bb6cce784e466cf397afada7721eb6c1682 Mon Sep 17 00:00:00 2001
From: Tom Kirkpatrick <tom@systemseed.com>
Date: Fri, 16 Mar 2012 21:22:23 +0100
Subject: [PATCH] [#1485942] - Only affect formflow fieldsets rather than any
 fieldset

---
 formflow.module |   41 +++++++++++++++++++++++++++++++++++------
 1 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/formflow.module b/formflow.module
index 4027c9d..cefa8bb 100644
--- a/formflow.module
+++ b/formflow.module
@@ -521,19 +521,39 @@ 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']));
   }
+
   $form['#current_group'] = $form_state['current_group'];
+
   // Build a trail to display at the top of the form
   $form['trail'] = array(
     '#theme' => 'formflow_wizard_trail',
@@ -541,7 +561,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';
@@ -551,13 +572,16 @@ function formflow_attach_groups(&$form, &$form_state, $display_mode){
       $form['trail']['#value'][] = '<span class="' . $class . '">' . $group->label . '</span>';
     }
   }
+
   // If there's still groups for this build mode, add some buttons
   if(count($form['trail']['#value'])){
+
     // Get the numeric position of the current group
     $form['#position'] = array_search($form['#current_group'], array_keys($form['#groups']));
     $form['formflow_actions'] = array(
       '#type' => 'actions'
     );
+
     // If this isn't the last group, show the back button
     if($form['#position'] > 0){
       $form['formflow_actions']['back'] = array(
@@ -571,6 +595,7 @@ function formflow_attach_groups(&$form, &$form_state, $display_mode){
         '#formflow' => true // Set a flag to preserve this over all formflow steps
       );
     }
+
     // If this isn't the last group, show the next button
     if(($form['#position'] + 1) < count($form['#groups'])){
       $form['formflow_actions']['next'] = array(
@@ -583,6 +608,7 @@ function formflow_attach_groups(&$form, &$form_state, $display_mode){
         '#formflow' => true // Set a flag to preserve this over all formflow steps
       );
     }
+
     // limit validation errors to only the form items in the current group
     foreach($form['#group_children'] as $element_name => $group){
       if($group == $form['#current_group']){
@@ -647,8 +673,11 @@ 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']){
-    $id = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $form['#display_mode'] . '_' . $group->group_name;
+  // Prepare some variables to use in the logic.
+  $view_mode = isset($form['#view_mode']) ? $form['#view_mode'] : 'form';
+  $id = $form['#entity_type'] . '_' . $form['#bundle'] . '_' . $view_mode . '_' . $group->group_name;
+  
+  if(empty($group->format_settings['instance_settings']['display_mode']) || $group->format_settings['instance_settings']['display_mode'] == $view_mode){
     // Prepare extra classes.
     $classes = array(
       'field-group-' . $group->format_type,
-- 
1.7.4.4

