Image attach module has a lil bug that i want to bring in to the consideration of Project Manager. When we want to display a field(image attach field) in views it wont display becuase the value passed to $image_node variable is NULL/Empty.
So I fixed this by changing the following line in image_attach_views_handler_field_iid.inc file:
function render($values) {
- $image_node = node_load($values->image_attach_iid); ---- Changed this line only
+ $image_node = node_load($values->nid);
I have been using drupal for a long time but this is my first bug report :)
Please do confirm me if you commit this change
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | image_attach_views_handler_field_iid.patch | 527 bytes | jadowd |
Comments
Comment #1
sunPlease submit a proper patch.
Comment #2
jadowd commentedHave you added this into the repository? It is a simple, yet important fix, but if you won't implement it because of the lack of a patch, then I will write the patch.
Thanks,
Comment #3
emdeex commentedI've used this patch, and it does fix the issue of not being able to view image nodes.
Comment #4
jadowd commentedSure... but will this be fixed in the next release of this module?
Comment #5
sunAgain, a proper patch is required. See http://drupal.org/patch
Comment #6
jadowd commentedHere you go... but really, it was all about the changing a few characters. Sun, you really could have just made the edit.
Comment #7
jadowd commentedComment #8
sunPlease compare to #360170: Hard-coded field name in Views handler of Image Attach and check whether there is not a better solution. Additionally, I'm not sure whether #220295: Views 2 Support in 6.x might alter this part of the Views integration anyway.
Aside from that, have a look at http://drupal.org/user/54136 and you might understand my reasoning.
Comment #9
joachim commentedhttp://drupal.org/node/220295 will almost certainly change this. We can probably do some subclassing from the general image field.
Comment #10
jadowd commentedYou guys lost me... Use the patch or don't, just let me know if this issue will be resolved in the next release.
Thanks,
Comment #11
mafioso commentedIn my case, the patch didn't really work. It worked only for my image nodes, but not for other nodes using image attach.
To work around the problem i changed the line in image_attach_views_handler_field_iid.inc file:
$image_node = empty($values->image_attach_iid) ? node_load($values->nid) : node_load($values->image_attach_iid);
I'm sure you guys have a better solution for this issue, and please resolve this issue in the next release :)
Thanks.
Comment #12
joachim commentedI really don't understand what you guys are trying to do with your views to need this code....
This makes no sense. Either you have an image node, and its nid is the nid that views passes you in the $values. Or you have another node with an attached image, and the nid of the attached image is $values->image_attach_iid. You can't use this one field for both cases!
At any rate, like sun says, we're going to be changing this stuff soon.
I think we should wait for the data storage to be changed by this patch first: #81102: Attach Multiple Images with image_attach using Drupal upload mechanism
Comment #13
theoldfather commentedthank you. this worked for me. i was trying to display an attached image field through views. the image was attached to an audio node.
Comment #14
emdalton commentedOk, I'm still having this problem with the July 13 dev build. I have created a slideshow view that selects a number of nodes of type "Image" and I attempt to display two fields, one for the attached image (in the "Preview" size) and one for the body text. I get the body text, but no image. The only way I am able to get an image to appear in Views 2.x is by selecting row of type "node," in which case I get the node title and a bunch of other cruft that I don't want. No value for the image is getting passed through Views in "field" mode. I tried faking out Views by using Contemplate to define the Teaser field as just the preview image (which worked in Views 1.x), but Contemplate values are only used in rows of type Node in Views 2.x, so I'm back to where I started.
I tried applying the patch in #6, and the patch failed.
When I look at the code, it looks like the relevant line has been changed to
$image_node = node_load($values->{$this->field_alias});and I'm not sure how to proceed with this adjustment. (Can I just replace "{$this->field_alias}" with "nid"?)
I looked through the links referenced in other posts here, and nearly all of them point to closed issues. I don't need or want to be able to attach multiple images to a node. I just need to have a slideshow that I can display on my front page that draws its images from a gallery my appropriately privileged users can add to. I used to be able to do this with Views and attached images. Should I be using some other method now? Any suggestions? I'd prefer not to have heavy plugin content (Flash, Java, etc.) on the main page of this site.
Comment #15
emdalton commentedI have confirmed that replacing
$image_node = node_load($values->{$this->field_alias});
with
$image_node = node_load($values->nid);
solves the image display problem with the July 13 build. I highly recommend that this change be included in the next development build, or if not, that an explanation be provided for the lack of support of images in views until circumstances change. I don't understand most of the debate above, but claiming Views 2.x support for images when it doesn't work makes no sense to me, and continuing to delay implementing a working fix because you might change something else down the road also doesn't make sense to me. I'm probably missing something in all this. But in any case, my thanks to the original poster for providing the fix.
Comment #16
joachim commentedYou're loading the wrong thing!
$values->nid is the nid of the CURRENT node.
What you want is the nid of the attached image.
What is your view meant to be showing?
Comment #17
emdalton commentedMy view is supposed to show a slideshow of images with accompanying node body text. It's working. Perhaps the context of which node we're looking for is already supplied by Views? Or perhaps the code should say {$this->nid} ?
Comment #18
joachim commentedA slideshow of what kind of nodes though? Image nodes or the nodes that attach them?
What are your filters?
Comment #19
emdalton commentedHere's the Views export (which didn't work before, but does work after the change):
I wasn't able to get any image attached to a node to show in any view other than one that showed the whole node, until I made the change. Now I can refer to the attached image as a "field," which is what I need to be able to do. I can even rewrite the output to get the results into a table format, which is what I wanted.
Depending on what I'm doing with the test server, you may be able to see the resulting view here: http://btest5.unh.edu
Comment #20
joachim commentedYour view is a view of *Image nodes*:
So of COURSE the image attach field is giving you the wrong thing!
The image attach field is for OTHER kinds of nodes that have an attached image.
Comment #21
emdalton commentedThank you. I reverted the code, then switched to field "image:image" and that fixed the problem. Sorry for the confusion, but the distinction between an image node and an attached image confused me. Perhaps it confused the original poster as well. Let's hope this thread helps explain it to anyone else who is confused.
Comment #22
emdalton commentedHm. I haven't actually tested image: attach, so I probably ought not to close this just yet. I'll test the original problem the OP reported later today. If someone else has already tested, feel free to close this.
Comment #23
sunFeel free to re-open this issue if you want to provide further information.