Summary
I have created a view which generates a block with 5 random images from the collected galleries, but when this block is displayed on the gallery-list page, no images appear and on a specific gallery-page it only shows images that are from other galleries or images that are currently shown on the gallery-page.
Problem
When the gallery-node is loaded and viewed, media_gallery_view() destroys the $node->media_gallery_media field and after that it is cached somewhere in the entity_load() stage. The view that tries to fetch 5 random images runs after the loads the node and gets the cached and thus broken version of the node and can't find the entry for the fid in the $node->media_gallery_media array.
Solution
I've attached a patch which restores the $node->media_gallery_media array in a hook which is called after field_attach_view(), so the node renders correctly but also restores its data-structure for future use.
Comment | File | Size | Author |
---|---|---|---|
#8 | media_gallery_views.tar_.gz | 1.89 KB | gnoddep |
#6 | view.php_.gz | 1.45 KB | gnoddep |
#4 | media_gallery-beta7-media_gallery_media.patch | 721 bytes | gnoddep |
media_gallery_fix-media_gallery_media-field.diff | 651 bytes | gnoddep |
Comments
Comment #1
gnoddep CreditAttribution: gnoddep commentedComment #2
gnoddep CreditAttribution: gnoddep commentedClosing this issue, because it seems to be fixed with beta7
Comment #3
gnoddep CreditAttribution: gnoddep commentedsorry, too soon, I was looking at a cached version.
Comment #4
gnoddep CreditAttribution: gnoddep commentedUpdated patch for beta7
Comment #5
carole CreditAttribution: carole commentedHow did you create the random image block?
Comment #6
gnoddep CreditAttribution: gnoddep commentedI've attached an export of the random images view I've created (view.php.gz).
Comment #7
lsolesen CreditAttribution: lsolesen commentedI cannot reproduce this issue on the latest dev. If it is still an issue for you, please reopen this issue.
Comment #8
gnoddep CreditAttribution: gnoddep commentedThis issue has not been resolved. Let me specify the issue:
I have a view (see album_list.view.php in the attached tar.gz) which generates a page of the teasers of all my albums. I also have a view (see random_images.view.php) which generates a block with 5 random images from albums new than 3 years, this block is displayed on all pages.
When media_gallery displays a teaser of an album-node, it destroys the $node->media_gallery_media array (see media_gallery.module:279):
It does not restore the array later on and drupal caches the node with the broken media_gallery_media array. So when the view that generates the block with random images is being run, it will use the database to find the images, but the rendering code can't find the image in the media_gallery_media array and will generate an img-tag with empty src-attribute.
The solution for this is to restore the media_gallery_media array in a hook that is called after media_gallery_view() (see the patch attached to this issue).
Comment #9
lsolesen CreditAttribution: lsolesen commented@gnoddep Ok. I missed that you were using two different views. Thought you were talking about the galleries page created by this module. For us to quickly review your patch, please recreate the problem using the media_dev install profile for the 1.x branch of media (off course you need to download views also). Create the views and attach them to this issue, so we can easily import them and see the problem and confirm that your patch resolves the issue. Thank you.
Comment #10
lsolesen CreditAttribution: lsolesen commentedTagging as a beta9-blocker.
Comment #11
ivnish CreditAttribution: ivnish commented