I created a content type with an image field, and created a few nodes. Then I created a views block with one field for the imagefield of these nodes.

The images displays correctly in nodes, but not showed in views.

Anyone know why this happen?

Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Maybe you don't have the right filter criteria, so you actually returns other nodes, then the one with imagefields?

So a views export would probably help here to see what you actually did.

featips’s picture

Another field is node title, which shows that I am returning correct nodes. Only the image field does not show.

I ever saw some post mentioned that need to use default image. so I also uploaded default image, but still the image field does not show in views.

esmerel’s picture

An export, link to the site, screenshot of the views config... Anything with more data would really help here.

seehawk’s picture

FileSize
31.07 KB

I'm running into a similar issue. In my case, I have a Views Slideshow view that uses a single image field with multiple images to populate the slideshow. I've also tried the same view using just Unformatted list as the formatter and had the same issue.

In all cases, the images will not display within a block. However, when you look at the slideshow in the preview area of the views interface, it displays correctly. Same goes for when I take Views Slideshow out of the equation. Regardless of the formatter I choose, no images display in the block.

My view has a page display, and when I feed that page the NID of a node with images, then the view displays correctly in the page. It seems to be just the block that's not working. Also, if I give the block a specific NID, then it will display the images as long as the block is not appearing on the same page as the node that's feeding the view. (so, if we have an NID of 1234, the view will display correctly on every page except 1234).

This is happening in Garland (as well as a custom theme). I've attached an export of the view. Any thoughts?

Edit: Also, I'm running Ctools 7.x-1.0-rc2 and Views 3.3.

dawehner’s picture

Personally i would post that in the vies slideshow issue queue as they know how the slideshow module works and maybe provide some guidance to fix the issue.

seehawk’s picture

The issue's not unique to Views Slideshow, though. It's happening even without the slideshow formatter, as mentioned above.

travist’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Needs review
FileSize
919 bytes

I am not totally sure if this is the solution to what you are seeing, but I was able to reproduce this when I set the default image within an Image field, I noticed that the view does not display the default image if there was none uploaded to the view. I did some digging and debugging and found that the view only will show the entity value for a field, and not the value that is populated within the $values array on get_value. I believe that views need to fallback to the $values array if a value is not set within the $entity.

Here is a patch that solved this issue for my use case.

Let me know if this patch needs to go in another issue....

Thanks,

Travis.

dawehner’s picture

Issue tags: +Needs tests

It kind of makes sense what you did here, though i'm wondering why you are the only person which sees this problem.

Mh this works fine for me, just added a default image to the image-field and created a node without this field.

As this is a really critical part of the code it would be somehow required to have a test which covers this bug. You don't have to write this one, as long you can explain how to reproduce it in detail, but you are sure welcomed to do so. Additional it would be cool if there were some inline documentation saying: hey what is going on with this ifs here ...

travist’s picture

Well, my specific use case was I was trying to fix an issue in the MediaFront module where if you create a media player playlist view, the default images were not showing up in the player if no image was uploaded. The code that I am basically calling to get the value of the image to display in the player provided a view is as follows...

$image = $field->get_value($values);

$field is the type views_handler_field_field, and $values is the values within the row of views. I noticed that when I make this call, the entity does NOT populate the image field with the default image object, however, the $values does contain the default image object. I figured that a good fix within views would be to have some form of generic fallback if no value is found within the entity. Apparently, the values 'could' contain data that is not present within the entity, which this patch does accomplish.

Let me know if I need to go into further detail on how to reproduce...

Thanks,

Travis.

admarble’s picture

I had the same problem and after super extensive search I found out that it was a relationship problem linking the image field to the product display instead of the actual product. A more detailed approach that worked perfect for me can be found Here. Hope this helps.

dawehner’s picture

Status: Needs review » Needs work
+++ b/modules/field/views_handler_field_field.incundefined
@@ -754,8 +754,13 @@ class views_handler_field_field extends views_handler_field {
+      $field_name = $this->handler_type . '_' . $this->field;

Can you explain this change here? Wouldn't it make sense to use $this->field_alias instead?

In general i'm really careful with changing anything there, because this can effect a lot of sites.

travist’s picture

I have not tested all the use cases but I do believe you are right in that $this->field_alias should work instead of $field_name = $this->handler_type . '_' . $this->field;.

Regarding your concerns, the following code represents existing behavior....

+++ b/modules/field/views_handler_field_field.incundefined
@@ -754,8 +754,13 @@ class views_handler_field_field extends views_handler_field {
+    else if (!empty($entity->{$this->definition['field_name']}[$langcode])) {
+      return $entity->{$this->definition['field_name']}[$langcode];

All that was added in this patch was an additional fallback to handle other cases where there are multiple values in the values array... This is typically the case for more complex field objects where other handlers may manage those row values. This piece of code is able to get the values where offsets are included.

+++ b/modules/field/views_handler_field_field.incundefined
@@ -754,8 +754,13 @@ class views_handler_field_field extends views_handler_field {
+      $field_name = $this->handler_type . '_' . $this->field;
+      $offset = $this->options['delta_offset'];
+      return !empty($values->{$field_name}[$offset]) ? $values->{$field_name}[$offset]['raw'] : array();

Let me know you thoughts.

Travis.

gyemeleth’s picture

I dont know if you need to add code for this. I had this same problem. What fixed it for me is that I have to add a 'relationship' on the far right hand side to the image that I want to display. When you add a relationship using the machine name of the image field you should have to go back and link it to the image that you want to display

lakenney’s picture

Issue summary: View changes

My solution was to create a custom content type with an image field and give it a name. Then when I create the view using the custom content type, all of the fields I used are available to me. I'm new to Drupal 8 so I don't know if this is what is intended, but that's what worked for me.

SseggembeMoses’s picture

This might come in late but sometimes you have to check whether you have a .htacess file in sites/default/files directory. If its not there, you can try to upload it there. It might help