Commit 98f9a396 authored by fago's avatar fago
Browse files

Issue #1614578 by theunraveler, fago | John Pitcairn: Allow other modules to...

Issue #1614578 by theunraveler, fago | John Pitcairn: Allow other modules to determine if collection item is empty, avoid saving empty item or rendering empty collection.
parent 28d43ae1
<?php
/**
* @file
* Contains API documentation and examples for the Field collection module.
*/
/**
* Alter whether a field collection item is considered empty.
*
* This hook allows modules to determine whether a field collection is empty
* before it is saved.
*
* @param boolean $empty
* Whether or not the field should be considered empty.
* @param FieldCollectionItemEntity $item
* The field collection we are currently operating on.
*/
function hook_field_collection_is_empty_alter(&$is_empty, FieldCollectionItemEntity $item) {
if (isset($item->my_field) && empty($item->my_field)) {
$is_empty = TRUE;
}
}
......@@ -719,6 +719,7 @@ function field_collection_field_is_empty($item, $field) {
*/
function field_collection_item_is_empty(FieldCollectionItemEntity $item) {
$instances = field_info_instances('field_collection_item', $item->field_name);
$is_empty = TRUE;
foreach ($instances as $instance) {
$field_name = $instance['field_name'];
......@@ -733,13 +734,16 @@ function field_collection_item_is_empty(FieldCollectionItemEntity $item) {
// field collection item is not empty.
foreach ($item->{$field_name}[$langcode] as $field_item) {
if (!module_invoke($field['module'], 'field_is_empty', $field_item, $field)) {
return FALSE;
$is_empty = FALSE;
}
}
}
}
}
return TRUE;
// Allow other modules a chance to alter the value before returning.
drupal_alter('field_collection_is_empty', $is_empty, $item);
return $is_empty;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment