Browse Source

Fixed issues with chaching. Fields now only load via ajax when fields are not hidden

Stephen Ficklin 7 years ago
parent
commit
1f22533972
2 changed files with 9 additions and 3 deletions
  1. 8 3
      tripal/includes/TripalEntityController.inc
  2. 1 0
      tripal/includes/tripal.entity.inc

+ 8 - 3
tripal/includes/TripalEntityController.inc

@@ -492,12 +492,12 @@ class TripalEntityController extends EntityAPIController {
       foreach ($queried_entities as $id => $entity) {
         $info = entity_get_info($entity->type);
         $field_cache = array_key_exists('field cache', $info) ? $info['field cache'] : FALSE;
-        $bundle = $entity->bundle;
+        $bundle_name = $entity->bundle;
 
         // Iterate through the field instances and find those that are set to
         // 'auto_attach' and which are attached to this bundle. Add all
         // fields that don't need auto attach to the field_ids array.
-        $instances = field_info_instances('TripalEntity', $bundle);
+        $instances = field_info_instances('TripalEntity', $bundle_name);
         foreach ($instances as $instance) {
           $field_name =  $instance['field_name'];
           $field = field_info_field($field_name);
@@ -539,9 +539,14 @@ class TripalEntityController extends EntityAPIController {
           // attach then we will ignore it. It can only be set by providing
           // the id in the $field_id array handled previously.
           else {
+            // We only load via AJAX if empty fields are not hidden.
+            $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+            $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle->id, 'hide');
             if (array_key_exists('settings', $instance) and
                 array_key_exists('auto_attach', $instance['settings']) and
-                $instance['settings']['auto_attach'] == FALSE) {
+                $instance['settings']['auto_attach'] == FALSE and
+                $hide_variable == 'show') {
+
                // Add an empty value. This will allow the tripal_entity_view()
                // hook to add the necessary prefixes to the field for ajax
                // loading.

+ 1 - 0
tripal/includes/tripal.entity.inc

@@ -314,6 +314,7 @@ function tripal_entity_access($op, $entity = NULL, $account = NULL, $entity_type
 function tripal_entity_view($entity, $type, $view_mode, $langcode) {
 
   if ($type == 'TripalEntity') {
+
     foreach (element_children($entity->content) as $child_name) {
 
       // Initailize the prefix and suffix for this field.