Kaynağa Gözat

reorganized panes template for readability

Stephen Ficklin 9 yıl önce
ebeveyn
işleme
87c4fd0b09

+ 95 - 79
tripal_panes/theme/templates/tripal_panes_generic.tpl.php

@@ -11,92 +11,14 @@ drupal_add_js('misc/collapse.js');
 drupal_add_js(drupal_get_path('module','tripal_panes') . '/theme/js/tripal_panes.js');
 
 // Get the variables passed into this template.
-$panes = $variables['element']['#panes'];
-$fields = $variables['element']['#fields'];
 $bundle = $variables['element']['#bundle'];
-
 $bundle_type = $bundle->name . '-' . $bundle->label;
 
 $content = '';
 $toc = '';
 $has_base_pane_only = TRUE;
 
-// Iterate through all of the panes.
-foreach ($panes AS $pane_id => $pane) {
-  if ($pane->name != 'te_base') {
-    $has_base_pane_only = FALSE;
-  }
-  $pane_settings = unserialize($pane->settings);
-  $table_layout_group = key_exists('table_layout', $pane_settings) ? $pane_settings['table_layout'] : array();
-
-  // Rearrange fields into groups for each pane
-  $pane_fields = $fields[$pane_id];
-
-  // Keyed by field's '#weight' and '#field_name so we can ksort() by weight
-  $weighed_fields = array();
-  foreach ($pane_fields as $field) {
-    $weighed_fields [$field['#weight'] . $field['#field_name']] = $field;
-  }
-  ksort($weighed_fields, SORT_NUMERIC);
-
-  // Render weighed fields
-  $table_layout = array();
-  $no_group = array();
-  $output = '';
-  $current_layout = '';
-  $counter = 0;
-  foreach ($weighed_fields AS $field) {
-    //Add CSS Class
-    $css_class = $field['#css_class'] ? ' ' . $field['#css_class'] : '';
-    $field['#prefix'] = '<div class="tripal_panes-field-wrapper' . $css_class . '">';
-    $field['#suffix'] = '</div>';
-
-    // The field is in a table
-    if (in_array($field['#field_name'], $table_layout_group)) {
-
-      if ($counter != 0 && $current_layout != 'Table') {
-        $output .= tripal_panes_generic_render_fields($no_group);
-        $no_group = array();
-      }
-      $table_layout [$field['#weight'] . $field['#field_name']] = $field;
-      $current_layout = 'Table';
-    }
-    // The field is not in a table
-    else {
-      if ($counter != 0 && $current_layout != 'Default') {
-        $output .= tripal_panes_generic_render_table($table_layout, $bundle_type);
-        $table_layout = array();
-      }
-      $no_group [$field['#weight'] . $field['#field_name']] = $field;
-      $current_layout = 'Default';
-    }
-    $counter ++;
-  }
-  if ($current_layout == 'Table') {
-    $output .= tripal_panes_generic_render_table($table_layout, $bundle_type);
-  }
-  else if ($current_layout == 'Default') {
-    $output .= tripal_panes_generic_render_fields($no_group);
-  }
-
-  // If this is a base content, do not organize the content in a fieldset
-  if ($pane->name == 'te_base') {
-    $content .= '<div class="tripal_pane-base_pane">' . $output . '</div>';
-  }
-  else {
-    $collapsible_item = array('element' => array());
-    $collapsible_item['element']['#description'] = $output;
-    $collapsible_item['element']['#title'] = $pane->label;
-    $collapsible_item['element']['#children'] = '';
-    $collapsible_item['element']['#attributes']['id'] = 'tripal_pane-fieldset-' . $pane->name;
-    $collapsible_item['element']['#attributes']['class'][] = 'tripal_pane-fieldset';
-    $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
-    $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
-    $toc_item_id = $pane_id;
-    $toc .= "<div class=\"tripal-panes-toc-list-item\"><a id=\"" . $pane->name . "\" class=\"tripal_panes-toc-list-item-link\" href=\"?pane=" . $pane->name . "\">" . $pane->label . "</a></div>";
-    $content .= theme('fieldset', $collapsible_item);
-  }
-}
+get_content($variables, $bundle_type, $content, $toc, $has_base_pane_only);
 
 if ($has_base_pane_only) { ?>
   <div id ="tripal-<?php print $bundle_type?>-contents-box"> <?php
@@ -119,6 +41,100 @@ else { ?>
   </table> <?php
 }
 
+/**
+ * Iterates through the panes and generates a conent string in HTML format.
+ *
+ * @param $variables
+ * @param $bundle_type
+ * @param $content
+ * @param $toc
+ * @param $has_base_pane_only
+ */
+function get_content($variables, $bundle_type, &$content, &$toc, &$has_base_pane_only) {
+  $panes = $variables['element']['#panes'];
+  $fields = $variables['element']['#fields'];
+
+  // Iterate through all of the panes.
+  foreach ($panes AS $pane_id => $pane) {
+    // If we have a pane other than the base pane then we have more than
+    // just the base.
+    if ($pane->name != 'te_base') {
+      $has_base_pane_only = FALSE;
+    }
+    $pane_settings = unserialize($pane->settings);
+    $table_layout_group = key_exists('table_layout', $pane_settings) ? $pane_settings['table_layout'] : array();
+
+    // Rearrange fields into groups for each pane
+    $pane_fields = $fields[$pane_id];
+
+    // Order the fields by their assigned weights.
+    $ordered_fields = array();
+    foreach ($pane_fields as $field) {
+      $ordered_fields[$field['#weight'] . $field['#field_name']] = $field;
+    }
+    ksort($ordered_fields, SORT_NUMERIC);
+
+    // Render fields
+    $table_layout = array();
+    $no_group = array();
+    $output = '';
+    $current_layout = '';
+    $counter = 0;
+    foreach ($ordered_fields AS $field) {
+      //Add CSS Class
+      $css_class = $field['#css_class'] ? ' ' . $field['#css_class'] : '';
+      $field['#prefix'] = '<div class="tripal_panes-field-wrapper' . $css_class . '">';
+      $field['#suffix'] = '</div>';
+
+      // The field is in a table
+      if (in_array($field['#field_name'], $table_layout_group)) {
+
+        if ($counter != 0 && $current_layout != 'Table') {
+          $output .= tripal_panes_generic_render_fields($no_group);
+          $no_group = array();
+        }
+        $table_layout [$field['#weight'] . $field['#field_name']] = $field;
+        $current_layout = 'Table';
+      }
+      // The field is not in a table
+      else {
+        if ($counter != 0 && $current_layout != 'Default') {
+          $output .= tripal_panes_generic_render_table($table_layout, $bundle_type);
+          $table_layout = array();
+        }
+        $no_group [$field['#weight'] . $field['#field_name']] = $field;
+        $current_layout = 'Default';
+      }
+      $counter ++;
+    }
+    if ($current_layout == 'Table') {
+      $output .= tripal_panes_generic_render_table($table_layout, $bundle_type);
+    }
+    else if ($current_layout == 'Default') {
+      $output .= tripal_panes_generic_render_fields($no_group);
+    }
+
+    // If this is a base content, do not organize the content in a fieldset
+    if ($pane->name == 'te_base') {
+      $content .= '<div class="tripal_pane-base_pane">' . $output . '</div>';
+    }
+    else {
+      $collapsible_item = array('element' => array());
+      $collapsible_item['element']['#description'] = $output;
+      $collapsible_item['element']['#title'] = $pane->label;
+      $collapsible_item['element']['#children'] = '';
+      $collapsible_item['element']['#attributes']['id'] = 'tripal_pane-fieldset-' . $pane->name;
+      $collapsible_item['element']['#attributes']['class'][] = 'tripal_pane-fieldset';
+      $collapsible_item['element']['#attributes']['class'][] = 'collapsible';
+      $collapsible_item['element']['#attributes']['class'][] = 'collapsed';
+      $toc_item_id = $pane_id;
+      $toc .= "<div class=\"tripal-panes-toc-list-item\"><a id=\"" . $pane->name . "\" class=\"tripal_panes-toc-list-item-link\" href=\"?pane=" . $pane->name . "\">" . $pane->label . "</a></div>";
+      $content .= theme('fieldset', $collapsible_item);
+    }
+  }
+}
+
+
 /**
  * A wrapper function for placing fields inside of a Drupal themed table.
  *