diff --git a/flexifield.module b/flexifield.module index 7b34f63..bb742fd 100644 --- a/flexifield.module +++ b/flexifield.module @@ -408,9 +405,33 @@ function flexifield_content_is_empty($aItem, $aFieldSettings) { $aChildFieldSettings = $aContentTypeInfo['fields'][$sChildFieldName]; if (is_array($aChildFieldSettings) && is_array($aChildFieldItems)) { foreach ($aChildFieldItems as $aChildFieldItem) { - if (is_array($aChildFieldItem) && !module_invoke($aChildFieldSettings['module'], 'content_is_empty', $aChildFieldItem, $aChildFieldSettings)) { - $bEmpty = FALSE; - break; + // ---------- LIIP FIX ------------------------------------------------- + // Strangely enough, when a nodereference field is used into a flexifield, + // the value is not stored the same way as when used outside a flexifield. + // + // Normaly the value is stored this way: + // + // $aChildField = array('nid' => THE VALUE) + // + // But in a flexifield, the value is stored with an additionnal array level, like this: + // + // $aChildField = array('nid' => array('nid' => THE VALUE)) + // + // Because of this, the normal routine will always consider the nodereference field is NOT empty. + // + // The following code corrects this problem. + if ($aChildFieldSettings['module'] === 'nodereference') { + if (is_array($aChildFieldItem) && !module_invoke($aChildFieldSettings['module'], 'content_is_empty', $aChildFieldItem['nid'], $aChildFieldSettings)) { + $bEmpty = FALSE; + break; + } + } + // ---------- END LIIP FIX --------------------------------------------- + else { + if (is_array($aChildFieldItem) && !module_invoke($aChildFieldSettings['module'], 'content_is_empty', $aChildFieldItem, $aChildFieldSettings)) { + $bEmpty = FALSE; + break; + } } } } @@ -418,7 +439,6 @@ function flexifield_content_is_empty($aItem, $aFieldSettings) { break; } } - return $bEmpty; }