The function file_view_multiple contains a bug that results in the items array being empty within template_preprocess_field thus nothing is shown. The issue is that the function file_view_multiple incorrectly places the file items in a subarray: "files" array rather than at the root of the build array. The function template_preprocess_field expects the renderable items to be located at the root of the renderable field build array not nested in a "files" array. This problem manifests itself when no video is seen on the node page. I think it is as simple as the below to fix.

Within the function file_view_multiple change this:

  foreach ($files as $delta=>$file) {
    $build['files'][$file->fid] = file_view($file, $view_mode, $langcode);
    $build['files'][$file->fid]['#weight'] = $weight;
    $weight++;
  }
 $build['files']['#sorted'] = TRUE;

to this

  foreach ($files as $delta=>$file) {
    $build[$file->fid] = file_view($file, $view_mode, $langcode);
    $build[$file->fid]['#weight'] = $weight;
    $weight++;
  }
  $build['#sorted'] = TRUE;

I'll submit a patch once I verify some more and have the time unless someone else does.

CommentFileSizeAuthor
#6 share.make_.yml2.54 KBoddz
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

oddz’s picture

Issue summary: View changes
AdamGerthel’s picture

I've tested your change but noticed some really strange stuff, and a lot of images stopped showing up.

oddz’s picture

That is unexpected because xdebug was explicitly used to step through the code section by section to get to this result. In looking at the function template_preprocess_field there is no way that the files array would be rendered with the existing implementtion.

Dave Reid’s picture

Status: Needs work » Postponed (maintainer needs more info)

This would break the entity_view() callback that we use. See also core's node_view_multiple() - it puts all the rendered nodes inside $build['nodes']. I don't see a regression with the way file fields are rendered using a view mode. Maybe you are usinga custom template_preproces_field() override?

oddz’s picture

I don't think so I stepped line by line through code using xdebug to get to that solution. I will have a more indepth look when I get time. For the time being that solution doesn't seem to have any ramifications for me. I'm running the latest d7 core. I can say for fact though that on my environment media isn't rendering without that modification.

oddz’s picture

FileSize
2.54 KB

This is the build file used which I ran into said issue.

Dave Reid’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I cannot reproduce this issue, and we cannot change the function's output as it wouldn't be backwards compatible.