Explorar el Código

Merge branch '7.x-3.x' of https://github.com/tripal/tripal into 7.x-3.x

Lacey Sanderson hace 7 años
padre
commit
28adc5dedf

+ 9 - 7
tripal/includes/TripalBundleController.inc

@@ -3,6 +3,7 @@
  * The Controller for Tripal data type entities
  */
 class TripalBundleController extends EntityAPIControllerExportable {
+
   public function __construct($entityType) {
     parent::__construct($entityType);
 
@@ -19,20 +20,20 @@ class TripalBundleController extends EntityAPIControllerExportable {
    * @return
    *   A type object with all default fields initialized.
    */
-  public function create(array $values = array()) {
+  public function create(array $values = []) {
     // Add values that are specific to our entity
-    $values += array(
+    $values += [
       'id' => '',
       'is_new' => TRUE,
       'data' => '',
-    );
+    ];
     $bundle = parent::create($values);
 
     // Allow modules to make additions to the entity when it's created.
     $modules = module_implements('bundle_create');
     foreach ($modules as $module) {
       $function = $module . '_bundle_create';
-      $function($bundle, array());
+      $function($bundle, []);
     }
 
     return $bundle;
@@ -73,8 +74,9 @@ class TripalBundleController extends EntityAPIControllerExportable {
 
           // If the field has no more instances then purge it too.
           if (count($field['bundles']) == 1 and
-              count($field['bundles']['TripalEntity']) == 1 and
-              in_array($bundle->name, $field['bundles']['TripalEntity'])) {
+            count($field['bundles']['TripalEntity']) == 1 and
+            in_array($bundle->name, $field['bundles']['TripalEntity'])
+          ) {
             field_purge_field($field);
           }
         }
@@ -98,7 +100,7 @@ class TripalBundleController extends EntityAPIControllerExportable {
       // overrides.
       foreach ($bundles as $id => $bundle) {
         if (entity_has_status($this->entityType, $bundle, ENTITY_IN_CODE)) {
-          entity_defaults_rebuild(array($this->entityType));
+          entity_defaults_rebuild([$this->entityType]);
           break;
         }
       }

+ 14 - 7
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -400,7 +400,7 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid){
   $ttype->condition($db_or);
   $result = $ttype->execute()->fetchObject();
 
-  tripal_update_cvtermpath_loop($rootid, $rootid, $cvid, $result->cvterm_id, 0, 0, array());
+  $result = tripal_update_cvtermpath_loop($rootid, $rootid, $cvid, $result->cvterm_id, 0, 0, array());
 
   $cterm = db_query(
     'SELECT *
@@ -411,9 +411,15 @@ function tripal_update_cvtermpath_root_loop($rootid, $cvid){
   );
 
   while($cterm_result = $cterm->fetchAssoc()) {
-    tripal_update_cvtermpath_root_loop($cterm_result['subject_id'], $cvid);
-  };
+    if ($result === 'LOOP'){
+      watchdog('debug', '<pre>$result: ' . print_r($result, TRUE) . '</pre>');
 
+      continue;
+    }
+    else {
+      tripal_update_cvtermpath_root_loop($cterm_result['subject_id'], $cvid);
+    }
+  }
 }
 
 /**
@@ -455,7 +461,9 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
           'pathdistance' => $depth,
         ));
       $rows = $query->execute();
-      if($rows) {
+      //watchdog('debug', '<pre>$rows: ' . print_r($rows, TRUE) . '</pre>');
+
+     // if($rows) {
         // Build the ID.
         $children_id = $origin . '|' . $child_id . '|' . $cv_id . '|' . $type_id;
         // Now check if the most recent entry already exists in the array.
@@ -468,7 +476,7 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
               watchdog('debug', '<pre>tripal_update_cvtermpath_loop  $result_of_loop_checker: ' . print_r($result_of_loop_checker, TRUE) . '</pre>');
               if ($result_of_loop_checker) {
                 watchdog('debug', 'Loop found exit the loop function');
-                break;
+                return 'LOOP';
               }
             }
           }
@@ -486,11 +494,10 @@ function tripal_update_cvtermpath_loop($origin, $child_id, $cv_id, $type_id, $de
         $cterm = $query->fetchAll();
 
         foreach ($cterm as $item) {
-          watchdog('message', '<pre>$loop_status: ' . print_r($loop_status, TRUE) . '</pre>');
           $increment_of_depth++;
           tripal_update_cvtermpath_loop($origin, $item->subject_id, $cv_id, $item->type_id, $depth + 1, $increment_of_depth, $array_of_children);
         }
-      }
+     // }
     }
   }
   catch(Exception $e){

+ 1 - 0
tripal_chado/api/tripal_chado.api.inc

@@ -161,6 +161,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   // Perform the query.
   $sql = $select . $from . $where;
   $records = chado_query($sql, $args);
+
   $transaction = db_transaction();
 
   print "\nNOTE: publishing records is performed using a database transaction. \n" .

+ 35 - 8
tripal_chado/includes/TripalFields/chado_linker__prop/chado_linker__prop_formatter.inc

@@ -24,14 +24,41 @@ class chado_linker__prop_formatter extends ChadoFieldFormatter {
     $field_name = $this->field['field_name'];
     $chado_table = $this->instance['settings']['chado_table'];
 
-    $content = '';
-    if ($items[0]['value']) {
-      $content = $items[0]['value'];
+    $content = array();
+    // If $items is not empty and it has more than one value all values need to
+    // be added to an array for display.
+    if ($items) {
+      if (count($items) > 1) {
+        foreach ($items as $index => $item) {
+          $content[$index] = $item['value'];
+        }
+      }
+      else {
+        $content = $items[0]['value'];
+      }
     }
-    $element[0] = array(
-      // We create a render array to produce the desired markup,
-      '#type' => 'markup',
-      '#markup' => $content,
-    );
+    // If more than one value has been found display all values in an unordered
+    // list.
+    if (count($content) > 1) {
+      $bullets = '<ul>';
+      $bullets .= '<li>';
+      $bullets .= implode("</li><li>", $content);
+      $bullets .= '</li>';
+      $bullets .= '</ul>';
+      $element[0] = array(
+        // We create a render array to produce the desired markup,
+        '#type' => 'markup',
+        '#markup' => $bullets,
+      );
+    }
+    // If it's a single value field display without bullets.
+    else {
+      $element[0] = array(
+        // We create a render array to produce the desired markup,
+        '#type' => 'markup',
+        '#markup' => $content,
+      );
+    }
+
   }
 }

+ 1 - 1
tripal_chado/includes/TripalFields/so__cds/so__cds.inc

@@ -62,7 +62,7 @@ class so__cds extends ChadoField {
     );
     $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
     $featurelocs = $feature->featureloc->feature_id;
-    return;
+
     foreach($featurelocs as $featureloc){
       // Generate a CDS sequence if one exsits for this feature alignment.
       $cds_sequence = tripal_get_feature_sequences(

+ 2 - 3
tripal_chado/includes/tripal_chado.field_storage.inc

@@ -1171,7 +1171,7 @@ function tripal_chado_field_storage_bundle_mapping_form_submit($form,
   $default = array(
     'table' => '',
     'has_all' => 'No',
-    'use_cvterm' => 'cv',
+    'use_cvterm' => '',
     'cv_id' => '',
     'use_linker' => 'No',
     'use_prop' => 'No',
@@ -1218,7 +1218,7 @@ function tripal_chado_field_storage_bundle_mapping_form_submit($form,
 
   // If the user selected to use the cvterm table then we have to
   // handle it specially.
-  if ($default['use_cvterm']) {
+  if ($default['use_cvterm'] == 'cv' and !empty($default['cv_id'])) {
     $storage_args['data_table'] = $default['table'];
     $storage_args['type_id'] = $form_state['values']['selected_cvterm_id'];
     $storage_args['type_value'] = '';
@@ -1226,7 +1226,6 @@ function tripal_chado_field_storage_bundle_mapping_form_submit($form,
       $storage_args['type_value'] = $default['cv_id'];
     }
     $storage_args['type_column'] = '';
-
     return;
   }
 

+ 13 - 11
tripal_chado/includes/tripal_chado.fields.inc

@@ -1614,17 +1614,19 @@ function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle
      $pkey = $schema['primary key'][0];
      // Get the list of existing property types for this table.
      $args = array();
-      $sql = "
-        SELECT DISTINCT P.type_id
-        FROM {" . $prop_table . "} P
-      ";
-      if (array_key_exists('type_id', $tschema['fields'])) {
-        $sql .= "
-            INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
-          WHERE T.type_id = :cvterm_id
-        ";
-        $args[':cvterm_id'] = $cvterm_id;
-      }
+     $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
+
+//       $sql = "
+//         SELECT DISTINCT P.type_id
+//         FROM {" . $prop_table . "} P
+//       ";
+//       if (array_key_exists('type_id', $tschema['fields'])) {
+//         $sql .= "
+//             INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
+//           WHERE T.type_id = :cvterm_id
+//         ";
+//         $args[':cvterm_id'] = $cvterm_id;
+//       }
 
      $props = chado_query($sql, $args);
      while ($prop = $props->fetchObject()) {

+ 17 - 1
tripal_ds/includes/views/tripal_ds.views.inc

@@ -73,7 +73,23 @@ function tripal_ds_views_data() {
       'handler' => 'views_handler_argument_string',
     ),
   );
-
+  $data['tripal_ds']['weight'] = array(
+    'title' => t('Weight'),
+    'help' => t('The weight as determined by the order in the Manage Display tab of the content type.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE, // This is use by the table display plugin.
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+    'argument' => array(
+      'handler' => 'views_handler_argument_string',
+    ),
+  );
   return $data;
 }
 

+ 68 - 63
tripal_ds/includes/views/tripal_ds.views_default.inc

@@ -4,58 +4,62 @@
 * Implements hook_views_default_views().
 */
 function tripal_ds_views_default_views() {
+  
+  $view = new view();
+  $view->name = 'tripal_content_type_toc';
+  $view->description = '';
+  $view->tag = 'default';
+  $view->base_table = 'tripal_ds';
+  $view->human_name = 'Tripal Content Type Table of Contents';
+  $view->core = 7;
+  $view->api_version = '3.0';
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
 
-$view = new view();
-$view->name = 'tripal_content_type_toc';
-$view->description = '';
-$view->tag = 'default';
-$view->base_table = 'tripal_ds';
-$view->human_name = 'Tripal Content Type Table of Contents';
-$view->core = 7;
-$view->api_version = '3.0';
-$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially. */
-
-/* Display: Master */
-$handler = $view->new_display('default', 'Master', 'default');
-$handler->display->display_options['title'] = 'Table of Contents';
-$handler->display->display_options['use_more_always'] = FALSE;
-$handler->display->display_options['access']['type'] = 'none';
-$handler->display->display_options['cache']['type'] = 'none';
-$handler->display->display_options['query']['type'] = 'views_query';
-$handler->display->display_options['exposed_form']['type'] = 'basic';
-$handler->display->display_options['pager']['type'] = 'full';
-$handler->display->display_options['pager']['options']['items_per_page'] = '10';
-$handler->display->display_options['style_plugin'] = 'default';
-$handler->display->display_options['row_plugin'] = 'fields';
-/* Field: Tripal Panes: Field Name */
-$handler->display->display_options['fields']['tripal_ds_field_name']['id'] = 'tripal_ds_field_name';
-$handler->display->display_options['fields']['tripal_ds_field_name']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['tripal_ds_field_name']['field'] = 'tripal_ds_field_name';
-$handler->display->display_options['fields']['tripal_ds_field_name']['label'] = '';
-$handler->display->display_options['fields']['tripal_ds_field_name']['exclude'] = TRUE;
-$handler->display->display_options['fields']['tripal_ds_field_name']['element_label_colon'] = FALSE;
-/* Field: Tripal Panes: Bundle ID */
-$handler->display->display_options['fields']['bundle']['id'] = 'bundle';
-$handler->display->display_options['fields']['bundle']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['bundle']['field'] = 'bundle';
-$handler->display->display_options['fields']['bundle']['label'] = '';
-$handler->display->display_options['fields']['bundle']['exclude'] = TRUE;
-$handler->display->display_options['fields']['bundle']['element_label_colon'] = FALSE;
-/* Field: Tripal Panes: Field Label */
-$handler->display->display_options['fields']['tripal_ds_field_label']['id'] = 'tripal_ds_field_label';
-$handler->display->display_options['fields']['tripal_ds_field_label']['table'] = 'tripal_ds';
-$handler->display->display_options['fields']['tripal_ds_field_label']['field'] = 'tripal_ds_field_label';
-$handler->display->display_options['fields']['tripal_ds_field_label']['label'] = '';
-$handler->display->display_options['fields']['tripal_ds_field_label']['alter']['alter_text'] = TRUE;
-$handler->display->display_options['fields']['tripal_ds_field_label']['alter']['text'] = '<a href="#" class="tripal_pane-toc-list-item-link" id ="[tripal_ds_field_name]">[tripal_ds_field_label] </a>';
-$handler->display->display_options['fields']['tripal_ds_field_label']['element_label_colon'] = FALSE;
-/* Contextual filter: Tripal Panes: Bundle ID */
-$handler->display->display_options['arguments']['bundle']['id'] = 'bundle';
-$handler->display->display_options['arguments']['bundle']['table'] = 'tripal_ds';
-$handler->display->display_options['arguments']['bundle']['field'] = 'bundle';
-$handler->display->display_options['arguments']['bundle']['default_action'] = 'default';
-$handler->display->display_options['arguments']['bundle']['default_argument_type'] = 'php';
-$handler->display->display_options['arguments']['bundle']['default_argument_options']['code'] = '$url = current_path();
+  /* Display: Master */
+  $handler = $view->new_display('default', 'Master', 'default');
+  $handler->display->display_options['title'] = 'Table of Contents';
+  $handler->display->display_options['use_more_always'] = FALSE;
+  $handler->display->display_options['access']['type'] = 'none';
+  $handler->display->display_options['cache']['type'] = 'none';
+  $handler->display->display_options['query']['type'] = 'views_query';
+  $handler->display->display_options['exposed_form']['type'] = 'basic';
+  $handler->display->display_options['pager']['type'] = 'full';
+  $handler->display->display_options['pager']['options']['items_per_page'] = '10';
+  $handler->display->display_options['style_plugin'] = 'default';
+  $handler->display->display_options['row_plugin'] = 'fields';
+  /* Field: Tripal Panes: Field Name */
+  $handler->display->display_options['fields']['tripal_ds_field_name']['id'] = 'tripal_ds_field_name';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['field'] = 'tripal_ds_field_name';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['label'] = '';
+  $handler->display->display_options['fields']['tripal_ds_field_name']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['tripal_ds_field_name']['element_label_colon'] = FALSE;
+  /* Field: Tripal Panes: Bundle ID */
+  $handler->display->display_options['fields']['bundle']['id'] = 'bundle';
+  $handler->display->display_options['fields']['bundle']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['bundle']['field'] = 'bundle';
+  $handler->display->display_options['fields']['bundle']['label'] = '';
+  $handler->display->display_options['fields']['bundle']['exclude'] = TRUE;
+  $handler->display->display_options['fields']['bundle']['element_label_colon'] = FALSE;
+  /* Field: Tripal Panes: Field Label */
+  $handler->display->display_options['fields']['tripal_ds_field_label']['id'] = 'tripal_ds_field_label';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['table'] = 'tripal_ds';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['field'] = 'tripal_ds_field_label';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['label'] = '';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['alter']['alter_text'] = TRUE;
+  $handler->display->display_options['fields']['tripal_ds_field_label']['alter']['text'] = '<a href="#" class="tripal_pane-toc-list-item-link" id ="[tripal_ds_field_name]">[tripal_ds_field_label] </a>';
+  $handler->display->display_options['fields']['tripal_ds_field_label']['element_label_colon'] = FALSE;
+  /* Sort criterion: Tripal Panes: Weight */
+  $handler->display->display_options['sorts']['weight']['id'] = 'weight';
+  $handler->display->display_options['sorts']['weight']['table'] = 'tripal_ds';
+  $handler->display->display_options['sorts']['weight']['field'] = 'weight';
+  /* Contextual filter: Tripal Panes: Bundle ID */
+  $handler->display->display_options['arguments']['bundle']['id'] = 'bundle';
+  $handler->display->display_options['arguments']['bundle']['table'] = 'tripal_ds';
+  $handler->display->display_options['arguments']['bundle']['field'] = 'bundle';
+  $handler->display->display_options['arguments']['bundle']['default_action'] = 'default';
+  $handler->display->display_options['arguments']['bundle']['default_argument_type'] = 'php';
+  $handler->display->display_options['arguments']['bundle']['default_argument_options']['code'] = '$url = current_path();
 $url_exploded = explode("/", $url);
 $tripal_entity_id = (int)$url_exploded[1];
 
@@ -66,20 +70,21 @@ $tripal_entity_id = (int)$url_exploded[1];
       ->fetchField();
 
 return $result;';
-$handler->display->display_options['arguments']['bundle']['summary']['number_of_records'] = '0';
-$handler->display->display_options['arguments']['bundle']['summary']['format'] = 'default_summary';
-$handler->display->display_options['arguments']['bundle']['summary_options']['items_per_page'] = '25';
-$handler->display->display_options['arguments']['bundle']['limit'] = '0';
+  $handler->display->display_options['arguments']['bundle']['summary']['number_of_records'] = '0';
+  $handler->display->display_options['arguments']['bundle']['summary']['format'] = 'default_summary';
+  $handler->display->display_options['arguments']['bundle']['summary_options']['items_per_page'] = '25';
+  $handler->display->display_options['arguments']['bundle']['limit'] = '0';
+
+  /* Display: Page */
+  $handler = $view->new_display('page', 'Page', 'page');
+  $handler->display->display_options['path'] = 'tripal_ct_toc';
 
-/* Display: Page */
-$handler = $view->new_display('page', 'Page', 'page');
-$handler->display->display_options['path'] = 'tripal_ct_toc';
+  /* Display: Block */
+  $handler = $view->new_display('block', 'Block', 'block');
+  $handler->display->display_options['defaults']['pager'] = FALSE;
+  $handler->display->display_options['pager']['type'] = 'none';
+  $handler->display->display_options['pager']['options']['offset'] = '0';
 
-/* Display: Block */
-$handler = $view->new_display('block', 'Block', 'block');
-$handler->display->display_options['defaults']['pager'] = FALSE;
-$handler->display->display_options['pager']['type'] = 'none';
-$handler->display->display_options['pager']['options']['offset'] = '0';
 
 $views[$view->name] = $view;
 

+ 23 - 0
tripal_ds/tripal_ds.install

@@ -38,8 +38,31 @@ function tripal_ds_schema() {
         'not null' => TRUE,
         'default' => ''
       ),
+      'weight' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 1,
+      ),
     ),
     'primary key' => array('id'),
   );
   return $schema;
 }
+
+/**
+ * Add a weight column to the tripal_ds table.
+ */
+function tripal_ds_update_7300() {
+  try {
+    db_add_field('tripal_ds', 'weight', array(
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 1,
+    ));
+  }
+  catch (\PDOException $e) {
+    $transaction->rollback();
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
+}

+ 67 - 44
tripal_ds/tripal_ds.module

@@ -85,7 +85,7 @@ function tripal_ds_bundle_delete($bundle){
   tripal_ds_table_column_delete($bundle);
 }
 
-/*
+/**
  * Implements hook_ds_field_settings_alter()
  */
 function tripal_ds_ds_field_settings_alter(&$field_settings, $form, $form_state){
@@ -123,39 +123,20 @@ function tripal_ds_ds_field_settings_alter(&$field_settings, $form, $form_state)
       }
     }
   }
+  // Update the menu items weight.
+  tripal_ds_toc_order($bundle_id, $form_state['values']['fields']);
 }
+
 /**
- * Implements hook_field_group_pre_render().
- *
- * This function gives you the oppertunity to create the given
- * wrapper element that can contain the fields.
- * In the example beneath, some variables are prepared and used when building the
- * actual wrapper element. All elements in drupal fapi can be used.
  *
- * Note that at this point, the field group has no notion of the fields in it.
- *
- * There is also an alternative way of handling this. The default implementation
- * within field_group calls "field_group_pre_render_<format_type>".
- * @see field_group_pre_render_fieldset.
- *
- * @param Array $elements by address.
- * @param Object $group The Field group info.
-
-function tripal_ds_field_group_pre_render(& $element, $group, & $form) {
-  watchdog('debug', '<pre>tripal_ds_preprocess_TripalEntity  $group: '. print_r($group, TRUE) .'</pre>');
-  if ($group->format_settings['formatter'] != 'open') {
-    $add['#prefix'] = '<div class="field-group-format ' . $classes . '">
-      <span class="field-group-format-toggler">' . check_plain(t($group->label)) . '</span>
-      <div class="field-group-format-wrapper" style="display: none;">';
-    $add['#suffix'] = '</div></div>';
-  }
-}
- */
-/**
  * Trigger the update to the tripal_ds table when a tripal pane is deleted.
+ *
+ * @param $bundle_name
+ * @param $field_label
+ * @param $field_name
+ * @param $entity_type
  */
 function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $entity_type){
-
   //Check the record does not already exist
   $tripal_ds_rows = db_select('tripal_ds', 'ds')
     ->fields('ds', array('tripal_ds_field_name', 'tripal_ds_field_label'))
@@ -163,7 +144,6 @@ function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $en
     ->condition('tripal_ds_field_label', $field_label, '=')
     ->condition('tripal_ds_field_name', $field_name, '=')
     ->execute()->fetchAll();
-
   if(!empty($tripal_ds_rows)){
     foreach ($tripal_ds_rows as $tripal_ds_row){
       if(($field_label == $tripal_ds_row->tripal_ds_field_label) && ($field_name == $tripal_ds_row->tripal_ds_field_name) && ($bundle_name == $tripal_ds_rows->bundle)) {
@@ -184,7 +164,7 @@ function tripal_ds_bundle_menu_item($bundle_name, $field_label, $field_name, $en
   }
 }
 
-/*
+/**
  * Implements hook_ds_layout_info() to define layouts from code in a module for
  * display suite
  */
@@ -206,6 +186,18 @@ function tripal_ds_ds_layout_info() {
   return $layouts;
 }
 
+/**
+ * Implements hook_form()
+ *
+ * Adds a confirmation message to applying default layout option in 'Manage
+ * Display'
+ *
+ * @param $form
+ * @param $form_state
+ * @param $bundle_name
+ *
+ * @return mixed
+ */
 function tripal_ds_update_layout_form($form, &$form_state, $bundle_name) {
   $form = array();
   $form['bundle_name'] = array(
@@ -226,6 +218,7 @@ function tripal_ds_update_layout_form($form, &$form_state, $bundle_name) {
 }
 
 /**
+ * Implements hook_form_submit()
  *
  * @param $form_state
  * @param $form
@@ -307,20 +300,10 @@ function tripal_ds_update_layout_form_submit($form, &$form_state) {
 }
 
 /**
- * @param $field
- * @param $bundle_name
-
-function tripal_ds_field_create_field($field, $bundle_name) {
-  //Build the rest of the passes parameters.
-  $field_name = str_replace('field_', '', $field['field_name']);
-  $group_field_name = 'gp_'.$field['field_name'];
-  //Create the field groups.
-  _additional_fields_field_group_info($bundle_name, $field_name, $group_field_name, $field_name);
-  //Place the field groups in the layout.
-  tripal_ds_update_ds_layout($bundle_name, $field_name, $group_field_name);
-}
- */
-/**
+ * Implements hook_form()
+ *
+ * Creates the button that creates an empty tripal pane.
+ *
  * @param $form
  * @param $form_state
  * @param $bundle_name
@@ -354,6 +337,7 @@ function tripal_ds_pane_addition_button_form($form, &$form_state, $bundle_name)
 }
 
 /**
+ * Implements hook_form_submit()
  *
  * @param $form_state
  * @param $form
@@ -460,6 +444,9 @@ function tripal_ds_field_display_alter(&$display, $context){
 
 */
 /**
+ * Identifies field_group parents to find tripal_panes and return that
+ * information to the function that calls it.
+ *
  * @param $field_name
  * @param $entity_type
  * @param $bundle
@@ -513,3 +500,39 @@ function tripal_ds_find_field_group_parent($field_name, $entity_type, $bundle, $
   return $field_groups_to_hide;
 
 }
+
+/**
+ * Updates the tripal_ds table with weight information of field_groups on
+ * save of "manage display' of content type. Weight is what is used to order
+ * the menu items.
+ *
+ * @param $bundle
+ * @param array $fields
+ */
+function tripal_ds_toc_order($bundle, $fields = array()){
+  // Find all menu items associated with the bundle id.
+  $menu_items = db_select('tripal_ds', 'ds')
+    ->fields('ds')
+    ->condition('bundle', $bundle, '=')
+    ->execute()->fetchAll();
+
+  // Now find all menu items in the $fields array
+  foreach ($menu_items as $menu_items => $menu_item) {
+    $toc_field_name = $menu_item->tripal_ds_field_name;
+    // Compare the field name from the table with the fields in the array.
+    if (array_key_exists($toc_field_name, $fields)) {
+      $weight = $fields[$toc_field_name]['weight'];
+      //If a weight is returned update the tripal_ds table.
+      if(!empty($weight)){
+        db_update('tripal_ds')
+          ->fields(array(
+            'weight' => $weight,
+          ))
+          ->condition('bundle', $bundle, '=')
+          ->condition('tripal_ds_field_name', $toc_field_name, '=')
+          ->execute();
+      }
+    }
+  }
+}
+