Problem/Motivation
For private files, file download system doesn't consider the published translation.
Steps to reproduce
This issue occurs when content is translatable. File upload field added on the content type is also translatable along with file upload file.
When the translation is published and if we try to access the file attached on translation, it fails.
- Create article content type.
- Add file upload field ensure that upload destination is set to private files
- Enable content translation, content moderation and add language.
- Enable article content type to use content moderation.
- Visit "admin/config/regional/content-language" and enable translation for all the article field including newly added private file field.
Ensure that file upload is also translated, not just alt text and name
- Create the English content for the node (don't upload file yet) and keep it in draft.
- Translate the above english content into other language, upload the private file and publish the translation.
- Check the file path on content translation i.e. /system/files/2025-06/abc.txt.
- Try to access the file using file path directly and see it doesn't work despite the translation is published.
- Publish the "English" translation
- Access the file using direct path like " /system/files/2025-06/abc.txt." and it works because English translation is published.
Proposed resolution
In file_get_file_references() we should ensure that we check the appropriate translation.
Remaining tasks
- MR
- Add tests
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
Original report by @simbaw
In my site, we enabled workflow and translation.
Reproduce steps:
1. Create a new content A and save to 'Draft'.
2. Translate content A and upload image to image filed, then save this translation to 'Published'.
3. View image by image link:
Actual: Anonymous User can not access this image.
Expect: Anonymous User can access this image.
Root cause: function file_get_file_references() returns is not correct.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | 3090998-30.diff | 3.92 KB | herved |
Issue fork drupal-3090998
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
simbaw commentedComment #8
borisson_This still applies, which is very unexpected, it however does not have any tests, so adding that tag.
Comment #9
rakhi soni commentedKindly review patch for version 9.4x,,
Comment #10
borisson_@Rakhi Soni this is exactly the same patch as #2, so this is not helpful.
In order to commit a bug fix we need an automated to test to prove that we've fixed the bug and ensure that we don't break it again in the future. For more information about writing tests in Drupal 8 see the following links:
I can't stop the test infrastructure, but I'll set it back to needs work to make sure we add the tests.
Comment #11
bnjmnmPre-emptively removing credit for #9 since it was an identical patch (i.e. unnecessary reroll)
Comment #14
mohit_aghera commentedComment #16
mohit_aghera commentedComment #17
mohit_aghera commentedComment #18
mohit_aghera commentedComment #19
smustgrave commentedLeft some comments on the MR but think adding return types to the content_translation module seem out of scope of the issue at hand.
Comment #20
mohit_aghera commentedTrue that.
However, if I don't add those, phpstan is failing for our test case class.
Job https://git.drupalcode.org/issue/drupal-3090998/-/jobs/5656011 has more information.
Comment #21
mohit_aghera commentedComment #22
oily commentedComment #23
smustgrave commentedThanks @oily but I reverted that change as it was out of scope and not related to this ticket.
I couldn't get the test-only job to run, was throwing some errors so I ran it locally
Switching to check the translation makes sense.
Comment #24
oily commented@smustgrave Thanks for reverting I agree with it (in hindsight)- seemed a good idea at the time : ).
Comment #25
anybody#2887696: Access denied to published private file if original translation is unpublished has been closed in favor of this - should be checked, if it's really duplicates.
Comment #26
catchOne question on the MR, also has merge conflicts.
Comment #28
herved commentedI rebased the MR on 11.x, I had to drop some commits and reverts that were causing conflicts so it'll be easier to rebase later.
We were previously using #2887696: Access denied to published private file if original translation is unpublished on our project but I can confirm this solution also covers it.
Also attaching static patch for composer.
Comment #30
herved commentedMR rebased, looks good IMO, moving to needs review and attaching current snapshot.
Comment #31
smustgrave commentedSuper small comment on MR. Rest LGTM.