From 839afb7478363c3e314e43761c709d71247993f6 Mon Sep 17 00:00:00 2001
From: Pierre Buyle <pierre@buyle.org>
Date: Mon, 12 Sep 2011 11:10:55 +0200
Subject: [PATCH 2/2] Issue #1276258 by mongolito404: Completely hide empty field collections.

---
 field_collection.module |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/field_collection.module b/field_collection.module
index 933ec4a..1ed54a4 100644
--- a/field_collection.module
+++ b/field_collection.module
@@ -654,6 +654,7 @@ function field_collection_field_formatter_info() {
         'delete' => t('Delete'),
         'add' => t('Add'),
         'description' => TRUE,
+        'hide_empty' => FALSE,
       ),
     ),
     'field_collection_view' => array(
@@ -664,6 +665,7 @@ function field_collection_field_formatter_info() {
         'delete' => t('Delete'),
         'add' => t('Add'),
         'description' => TRUE,
+        'hide_empty' => FALSE,
       ),
     ),
   );
@@ -700,6 +702,12 @@ function field_collection_field_formatter_settings_form($field, $instance, $view
     '#default_value' => $settings['description'],
     '#description' => t('If enabled and the add link is shown, the field description is shown in front of the add link.'),
   );
+  $elements['hide_empty'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Hide empty collection.'),
+      '#default_value' => $settings['hide_empty'],
+      '#description' => t('If enabled, nothing will be displayed for an empty collection (not even the add link).'),
+  );
   return $elements;
 }
 
@@ -726,6 +734,11 @@ function field_collection_field_formatter_view($entity_type, $entity, $field, $i
   $element = array();
   $settings = $display['settings'];
 
+  // Don't display anything for an empty collection.
+   if (empty($items) && !empty($settings['hide_empty'])) {
+     return NULL;
+   }
+
   switch ($display['type']) {
     case 'field_collection_list':
 
-- 
1.7.1

