The content of the imagefield_crop field is being deleted when saving an entity after upgrading to Drupal 7.29.

This core regression bug was created for the Taxonomy module and seemed related, but does not address contrib modules. :(

To reproduce this bug:

  1. Create a new piece of content and upload an image to the imagefield_crop field
  2. Save
  3. Verify image is saved (it should be visible and stored)
  4. Edit the same node but don't modify the imagefield_crop field
  5. Save
  6. The image has been deleted from the node/profile/entity

The new call to file_download_access($file->uri) (line 515 of file.module as of Drupal 7.29) seems to have triggered this issue.

Comments

citricguy’s picture

Title: Imagefield_crop field content deleted after entity save » Imagefield_crop field content deleted after entity save after upgrade to Drupal 7.29
citricguy’s picture

This issue is resolved by adding a call to hook_file_download().

The below code likely has issues, but it does work for me.

I added it to the bottom imagefield_crop.module

/**
 * Implements hook_file_download().
 */
function imagefield_crop_file_download($uri) {
  return file_file_download($uri, 'imagefield_crop');
}

There are a few additional details here if anyone wants to dig in.

David_Rothstein’s picture

Just to follow up here, it looks like only the 7.x-2.x branch of the module has this problem (because 7.x-1.x doesn't define its own field)?

I was able to reproduce it using 7.x-2.0, but the core patches from comment #42 onward in #2305017: Regression: Files or images attached to certain core and non-core entities are lost when the entity is edited and saved seem to take care of fixing it, so I think this might get fixed in core.

However, code similar to the above would make sense for this module to add anyway, since otherwise there will be problems on sites that use private files (regardless of Drupal 7.29 or not); for example, problems with end users not being able to view images associated with Image Cropped fields on those sites even when they are supposed to.