Selaa lähdekoodia

Fixed a few bugs

Stephen Ficklin 7 vuotta sitten
vanhempi
commit
a9a939f5a3

+ 1 - 0
tripal/api/tripal.entities.api.inc

@@ -559,6 +559,7 @@ function tripal_refresh_bundle_fields($bundle_name) {
         array('%bundle' => $bundle_name));
     return FALSE;
   }
+
   // Allow modules to add fields to the new bundle.
   $modules = module_implements('bundle_fields_info');
   foreach ($modules as $module) {

+ 1 - 2
tripal/includes/tripal.fields.inc

@@ -749,9 +749,8 @@ function tripal_field_formatter_settings_summary($field, $instance, $view_mode)
   $formatter_class = $field['type'] . '_formatter';
   if (tripal_load_include_field_class($formatter_class)) {
     $formatter = new $formatter_class($field, $instance);
-    $formatter->settingsSummary($view_mode);
+    return $formatter->settingsSummary($view_mode);
   }
-  return $formatter;
 }
 
 /**

+ 19 - 3
tripal/tripal.module

@@ -1025,19 +1025,35 @@ function tripal_field_display_alter(&$display, $context){
 }
 
 /**
- *  Implements _field_group_table_rows_alter().
+ * Implements hook_field_group_table_rows_alter().
+ *
+ * This hook is used for hiding empty rows in a Field Group Table field group.
+ *
  * @param $element
+ *   The field group object.
  * @param $children
+ *   An array of field names that are cpntained in the field group
  */
 function tripal_field_group_table_rows_alter(&$element, &$children) {
+
+  // Iterate through the children of this table field group.
   foreach ($children as $index => $child) {
     if (is_array($element[$child])) {
       $bundle = $element[$child]['#bundle'];
       $bundle_info = tripal_load_bundle_entity(array('name' => $bundle));
+
+      // If the hide empty variable is turned on then remove fields from
+      // the field group.
       $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id, '');
       if($hide_variable == 'hide'){
-        if ($element[$child][0]['#markup'] == NULL) {
-          // This is an empty row, remove it
+        $items = $element[$child]['#items'];
+        // Case #1: there are no items.
+        if (count($items) == 0) {
+          unset($children[$index]);
+          unset($element[$child]);
+        }
+        // Case #2: there is one item but the value is empty.
+        if (count($items) == 1 and array_key_exists('value', $items[0]) and empty($items[0]['value'])) {
           unset($children[$index]);
           unset($element[$child]);
         }

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

@@ -1573,17 +1573,18 @@ 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 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()) {
 

+ 7 - 8
tripal_ds/tripal_ds.module

@@ -438,18 +438,17 @@ function tripal_ds_field_display_alter(&$display, $context){
   $bundle_info = tripal_load_bundle_entity(array('name' => $bundle));
   $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id, '');
 
-  if($field_name && ($hide_variable == 'hide')){
+  if ($field_name && ($hide_variable == 'hide')) {
     $field = field_get_items('TripalEntity', $context['entity'], $field_name);
-    if($field) {
-      if(tripal_field_is_empty($field, $field)) {
+    if ($field) {
+      if (tripal_field_is_empty($field, $field)) {
         $parent_field_info = tripal_ds_find_field_group_parent($field_name, 'TripalEntity', $bundle, $context);
-        if(!empty($parent_field_info)){
-          $increment = 0;
-          foreach($parent_field_info as $parent_fields => $parent_field){
+        if (!empty($parent_field_info)) {
+          foreach ($parent_field_info as $parent_key => $parent_field){
             // Stop the right rail element from rendering.
-            drupal_add_css('.'.$parent_field_info[$increment].' {display:none;}', 'inline');
+            drupal_add_css('.' . $parent_field_info[$parent_key] . ' {display:none;}', 'inline');
             // Hide any associated menu links.
-            drupal_add_css('#'.$parent_field_info[$increment].' {display:none;}', 'inline');
+            drupal_add_css('#' . $parent_field_info[$parent_key] . ' {display:none;}', 'inline');
           }
         }
       }