Problem/Motivation

The page (render) cache is cached separately from the view result. If a user opens the media browser, everything gets put into both caches, however, if someone deletes a file that is in the view result, this exception is thrown when you reload the media browser:

EntityMalformedException: Missing bundle property on entity of type file. in entity_extract_ids()

This happens because of this code in template_preprocess_media_views_view_media_browser():

$files = file_load_multiple($fids);

// Render the preview for each file.
$params = media_get_browser_params();
$view_mode = isset($params['view_mode']) ? $params['view_mode'] : 'preview';

foreach ($vars['rows'] as $index => $row) {
  $file = $files[$row->fid];
  // Add url/preview to the file object.
  media_browser_build_media_item($file, $view_mode);
  $vars['rows'][$index] = $file;
  $vars['rows'][$index]->preview = $file->preview;
}

Since the query result is cached, and a fid from that result has been deleted, then file_load_multiple() will not return the same list of files that was passed into it.

Then the first argument passed to media_browser_build_media_item() is NULL

Proposed resolution

Ideally, we shouldn't be making database queries from the theme/template layer, but since changing that would take a major refactoring, it seems wiser to simply add a check that would ensure that the file being accessed actually exists in the array.

Remaining tasks

  1. Write Patch

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davidwbarratt created an issue. See original summary.

davidwbarratt’s picture

Issue summary: View changes
davidwbarratt’s picture

Status: Active » Needs review
FileSize
675 bytes

Attached is a patch that fixes the problem.

davidwbarratt’s picture

Issue summary: View changes
Dave Reid’s picture

Priority: Critical » Major
Status: Needs review » Reviewed & tested by the community

Dave Reid’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.