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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gnoddep’s picture

Status: Active » Needs review
gnoddep’s picture

Status: Needs review » Closed (fixed)

Closing this issue, because it seems to be fixed with beta7

gnoddep’s picture

Status: Closed (fixed) » Needs review

sorry, too soon, I was looking at a cached version.

gnoddep’s picture

Version: 7.x-1.0-beta6 » 7.x-1.0-beta7
FileSize
721 bytes

Updated patch for beta7

carole’s picture

How did you create the random image block?

gnoddep’s picture

FileSize
1.45 KB

I've attached an export of the random images view I've created (view.php.gz).

lsolesen’s picture

Status: Needs review » Closed (cannot reproduce)

I cannot reproduce this issue on the latest dev. If it is still an issue for you, please reopen this issue.

gnoddep’s picture

Status: Closed (cannot reproduce) » Active
FileSize
1.89 KB

This 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):

  // For the teaser, only the first thumbnail needs to be displayed, so remove the
  // rest from the node's field data, so that the field formatter doesn't waste
  // time building the render structure for items that won't be shown.
  if ($view_mode == 'teaser') {
    if (!empty($node->media_gallery_media[LANGUAGE_NONE])) {
      $first_item = array_shift($node->media_gallery_media[LANGUAGE_NONE]);
      $node->media_gallery_media[LANGUAGE_NONE] = array($first_item);
    }
  }

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).

lsolesen’s picture

Status: Active » Needs work

@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.

lsolesen’s picture

Issue tags: +Beta9-blocker

Tagging as a beta9-blocker.

ivnish’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)
Issue tags: -