Browse Source

changes to ignore the hide empty field setting when the ajax is turned on

Shawna Spoor 6 years ago
parent
commit
fc13e22334

+ 7 - 5
tripal/tripal.module

@@ -1523,9 +1523,10 @@ function tripal_field_display_TripalEntity_alter(&$display, $context){
   $bundle_info = tripal_load_bundle_entity(array('name' => $bundle));
 
   // Hide fields that are empty, but only if the hide_empty_field variable
-  // is set to 'hide' for this bundel.
+  // is set to TRUE for this bundle and ajax load is turned off.
   $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id);
-  if($hide_variable == TRUE){
+  $ajax_field = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
+  if($hide_variable === TRUE && $ajax_field === FALSE){
     $item = field_get_items('TripalEntity', $context['entity'], $field_name);
     if($item) {
       $field = field_info_field($field_name);
@@ -1555,10 +1556,11 @@ function tripal_field_group_table_rows_alter(&$element, &$children) {
       $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.
+      // If the hide empty variable is turned on and ajax load is turned off
+      // then remove fields from the field group.
       $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id);
-      if($hide_variable == TRUE){
+      $ajax_field = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
+      if($hide_variable == TRUE && $ajax_field == FALSE){
         $items = $element[$child]['#items'];
         // Case #1: there are no items.
         if (count($items) == 0) {

+ 1 - 1
tripal_ds/tripal_ds.module

@@ -470,7 +470,7 @@ function tripal_ds_field_display_alter(&$display, $context){
     $hide_variable = tripal_get_bundle_variable('hide_empty_field', $bundle_info->id);
     $ajax_variable = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
 
-    if ($field_name && ($hide_variable == TRUE)) {
+    if ($field_name && ($hide_variable == TRUE) && ($ajax_variable == FALSE)) {
       $item = field_get_items('TripalEntity', $context['entity'], $field_name);
       $field = field_info_field($field_name);
       if ($item) {

+ 21 - 5
tripal_ws/includes/TripalWebService/TripalContentService_v0_1.inc

@@ -249,7 +249,12 @@ class TripalContentService_v0_1 extends TripalWebService {
     // If the entity is set to hide fields that have no values then we
     // want to honor that in the web services too.
     $hide_fields = tripal_get_bundle_variable('hide_empty_field', $bundle->id);
-
+    $ajax_field = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
+    // If ajax is turned off the hide fields functionality will be handled by 
+    // javascript so change the $hide_fields variable to false to avoid any actions.
+    if ($ajax_field == TRUE) {
+      $hide_fields = FALSE;
+    }
     // Get information about the fields attached to this bundle and sort them
     // in the order they were set for the display.
     $instances = field_info_instances('TripalEntity', $bundle->name);
@@ -320,7 +325,7 @@ class TripalContentService_v0_1 extends TripalWebService {
           $this->addResourceProperty($resource, $term, $service_path . '/' . $entity->id . '/' . urlencode($term['name']), array('lowercase', 'spacing'));
         }
         else {
-          if ($hide_fields == 'show') {
+          if ($hide_fields == FALSE) {
             $this->addResourceProperty($resource, $term, NULL, array('lowercase', 'spacing'));
           }
         }
@@ -341,6 +346,12 @@ class TripalContentService_v0_1 extends TripalWebService {
     // If the entity is set to hide fields that have no values then we
     // want to honor that in the web services too.
     $hide_fields = tripal_get_bundle_variable('hide_empty_field', $bundle->id);
+    $ajax_field = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
+    // If ajax is turned off the hide fields functionality will be handled by 
+    // javascript so change the $hide_fields variable to false to avoid any actions.
+    if ($ajax_field == TRUE) {
+      $hide_fields = FALSE;
+    }
 
     // Get the field  settings.
     $field_name = $field['field_name'];
@@ -371,7 +382,7 @@ class TripalContentService_v0_1 extends TripalWebService {
       }
     }
 
-    if ($hide_fields == 'hide' and empty($values[0])) {
+    if ($hide_fields == TRUE and empty($values[0])) {
       return;
     }
 
@@ -437,7 +448,12 @@ class TripalContentService_v0_1 extends TripalWebService {
     // If the entity is set to hide fields that have no values then we
     // want to honor that in the web services too.
     $hide_fields = tripal_get_bundle_variable('hide_empty_field', $bundle->id);
-
+    $ajax_field = tripal_get_bundle_variable('ajax_field', $bundle_info->id);
+    // If ajax is turned off the hide fields functionality will be handled by 
+    // javascript so change the $hide_fields variable to false to avoid any actions.
+    if ($ajax_field == TRUE) {
+      $hide_fields = FALSE;
+    }
     $new_value = '';
     // If the value is an array rather than a scalar then map the sub elements
     // to controlled vocabulary terms.
@@ -446,7 +462,7 @@ class TripalContentService_v0_1 extends TripalWebService {
       foreach ($value as $k => $v) {
 
         // exclude fields that have no values so we can hide them
-        if (!isset($v) and $hide_fields == 'hide') {
+        if (!isset($v) and $hide_fields == TRUE) {
           continue;
         }