From 9051718d69e842c553c1a7d30cfddddb1d147eab Mon Sep 17 00:00:00 2001 From: Pierre Buyle Date: Mon, 14 Nov 2011 10:21:02 +0100 Subject: [PATCH] Issue #1276258 by mongolito404: Completely hide empty field collections. --- field_collection.module | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/field_collection.module b/field_collection.module index a43a559..92dff9b 100644 --- a/field_collection.module +++ b/field_collection.module @@ -687,6 +687,7 @@ function field_collection_field_formatter_info() { 'delete' => t('Delete'), 'add' => t('Add'), 'description' => TRUE, + 'hide_empty' => FALSE, ), ), 'field_collection_view' => array( @@ -698,6 +699,7 @@ function field_collection_field_formatter_info() { 'add' => t('Add'), 'description' => TRUE, 'view_mode' => 'full', + 'hide_empty' => FALSE, ), ), 'field_collection_fields' => array( @@ -705,6 +707,7 @@ function field_collection_field_formatter_info() { 'field types' => array('field_collection'), 'settings' => array( 'view_mode' => 'full', + 'hide_empty' => FALSE, ), ), ); @@ -763,6 +766,13 @@ function field_collection_field_formatter_settings_form($field, $instance, $view ); } + $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; } @@ -801,6 +811,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