I have a custom content type that uses imagefield so a user can upload an image.

I created a new view page and made a table that shows all of these nodes. It shows the nodes title as well as a thumbnail (imagecache) of the image that the user uploaded.

If the user did not upload an image then views is printing broken images (since there is no actual image to print)

How can I fix this?

Comments

merlinofchaos’s picture

Project: Views (for Drupal 7) » ImageField
Version: 5.x-1.5 » 5.x-1.1

Imagefield generates those links in handlers that it provides to Views.

j0k3z’s picture

Thanks for a quick response.

So what can I do? If a user has not uploaded an image can views provide a default image somehow?

greggles’s picture

Title: Views generating broken image links » views provide default image
Category: bug » feature

I see a couple options:

1. Make the image field required (though I imagine that won't work, but at least it's easy)
2. Use a views theme function - http://drupal.org/node/128741
3. A new feature in the formatters that provides a default image if no image was selected. I know that I've needed this before and I got around it with a theme fix (complex and I no longer have the code, so I can't/won't provide it - besides, it's not the good way to fix the problem).

moshe weitzman’s picture

I have needed this too. I love #3 - formatter feature. But does the formatter even get called when there is no value?

moshe weitzman’s picture

Title: views provide default image » default image formatter in Views

imagefield 5.2 will have default image support. it is already in CVS, but apparently uploading the default image is broken ATM. I don't know how well the default image is integrated with Views. The formatter would be lovely.

moshe weitzman’s picture

Priority: Normal » Critical

I figured out why this does not work. Now I just need some help finding the right fix. Our formatter receives "incomplete" data when called from a View as compared to called during a node_view(). Specifically, it performs this test before emitting a default image:

elseif ($field['widget']['use_default_image'] && is_array($field['widget']['default_image'])) {

The problem is that $field['widget'] only contains a 'label' element. It has no 'use_default_image' so the test fails and nothing gets emitted.

jpetso’s picture

'widget' members are not supplied by views, and probably shouldn't be. In filefield, I recently needed to migrate a remotely similar setting from hook_widget_settings() to hook_field_settings() because it's not a widget setting really. (Also, $field can be read by the formatter, $field['widget'] can't.)

I might be wrong, but the default image doesn't really sound like it should be a widget setting, does it? Anyways, you don't have lots of possibilities to get $field['widget'] from the formatter.

ms2011’s picture

@moshe weitzman: Re. imagefield.module: Everything we need is already provided by views.

KarenS explains here:

http://drupal.org/node/117621

Patch for imagefield.module is here:

http://drupal.org/node/180592#comment-658982

moshe weitzman’s picture

Status: Active » Closed (duplicate)

ok, lets follow the patch at http://drupal.org/node/180592.