Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
With a combination of Entity Cache, File Entity and private files:
When using the "replace" file option, users get "access denied" from file_file_download() to the new file because any entities where the file is referenced still have the old file path. The entities need their caches cleared as well.
Here's a workaround for it although a proper patch would probably be better:
/**
* Implements hook_entity_update().
*/
function modulename_entity_update($entity, $type) {
if ($type == 'file') {
// Clear caches of entities where file is used on update.
foreach (file_usage_list($entity) as $usage) {
foreach ($usage as $entity_type => $entity_ids) {
$entity_info = entity_get_info($entity_type);
$entities = empty($entity_info) ? NULL : entity_load($entity_type, array_keys($entity_ids));
foreach ($entities as $id => $entity) {
cache_clear_all($id, 'cache_entity_' . $entity_type);
}
}
}
}
}
Comments
Comment #1
sheise CreditAttribution: sheise commented