From d428068a4b6254ce511ff5c562bedd80dcdbd521 Mon Sep 17 00:00:00 2001 From: Ryan Jacobs Date: Wed, 24 Jul 2013 17:14:56 -0500 Subject: [PATCH] Issue #1928178 by rjacobs: Hide empty fields that do not use DB for storage. --- computed_field.module | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/computed_field.module b/computed_field.module index c7bff05..97029d1 100644 --- a/computed_field.module +++ b/computed_field.module @@ -305,6 +305,7 @@ function computed_field_field_formatter_info() { */ function computed_field_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) { $element = array(); + $data_to_display = FALSE; // Special case formatter that returns the raw computed values without any display code processing if ($display['type'] == "computed_field_computed_value") { @@ -343,6 +344,11 @@ function computed_field_field_formatter_view($entity_type, $entity, $field, $ins else { eval($field['settings']['display_format']); } + + // Track if any of our items produce non-empty output. + if (!empty($display_output) || is_numeric($display_output)) { + $data_to_display = TRUE; + } // Output the formatted display item switch ($display['type']) { @@ -357,6 +363,12 @@ function computed_field_field_formatter_view($entity_type, $entity, $field, $ins break; } } + // If all items are empty then we should not return anything. This helps + // ensure that empty fields are not displayed at all. This check does not + // apply to fields stored in the DB as those are instead checked on save. + if (isset($field['settings']['store']) && !$field['settings']['store'] && !$data_to_display) { + return; + } return $element; } -- 1.7.7.5 (Apple Git-26)