Hi Folks,

1. CCK - 6.x-2.1
2. Imagfield - 6.x-3.0-beta1
3. Permissions files directory - 774
4. Download Method - public
5. Imagefield Config - Multiple Images
6. Expected Result: I expect that when no picture is uploaded, that the $field_pictures Array is empty
7. Unexpected Result: Though no picture is uploaded to a particular node, the $field_pictures Array has an entry.

PROBLEM DESCRIPTION:

After upgrading from 6.x-3.0-alpha4 to 6.x-3.0-beta1 my custom template did not work as expected. I had included an if statement in my template, which basically checks, if the node has pictures, if not it would show some text, if it did include pictures, it would show an imagecache-processed thumbnail.

Before it worked like this:


<?php if($field_pictures): ?>
      
     Show Images 

<?php else: ?>
    
    Show Text

<?php endif; ?>

Now (after the upgrade) I need this statement for a workaround:

		<?php if (!empty($field_pictures[0]['status'])): ?>

The print_r for the supposedly empty $field_pictures shows this:

Array ( [0] => Array ( [view] => ) )

I really don't know if this is a result of my poor php knowledge or a bug report or simply a logical mistake by me. It just doesn't feel right to check the variable like this <?php if (!empty($field_pictures[0]['status'])): ?> instead of this <?php if($field_pictures): ?> after upgrading.

Any hints and help are really appreciated.

Comments

quicksketch’s picture

As far as I know, this is the usual behavior. If you have textfields (or any other type of CCK field), they also make an entry in the node like $node['field_textfield'][0]['value'], even though 'value' is NULL. There may have been a change in FileField (possibly #367267: Compatibility issues with Content Multigroup?) that would cause FileField to suddenly have this behavior, but I don't think it's a bad thing if FileField now behaves like other CCK fields.

theusualsuspect’s picture

then it must be something in filefield I guess. It really just happened while upgrading filefield and imagefield last night.

Another question though: Would that be then the best practice to check if the imagefield is empty? <?php if (!empty($field_pictures[0]['status'])): ?>

quicksketch’s picture

The best thing to check would be the 'fid' (File ID) which will be 0 if there isn't a real file. Status isn't actually a good thing to check, because that refers to whether or not the file is permanent. A file is not permanent (for example) when you've uploaded an image and then use the preview button before the node has been saved, yet you would still want the image to still show up in the themed preview.

if (!empty($field_pictures[0]['fid'])):

theusualsuspect’s picture

Thanks quicksketch. I appreciate it.

quicksketch’s picture

It looks like this bug (or "intended behavior") was added in #20 of Provide Compatibility with Content Multigroup, in which FileField needs to act like other fields when its value is empty. Apologies to everyone for the changed behavior, but it looks like it will stay this way.

quicksketch’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.