- First commit to issue fork.
- @jumpsuitgreen opened merge request.
- πΊπΈUnited States jumpsuitgreen
Attached is the patch I'm using in production in case anyone needs it.
- Status changed to Needs work
almost 2 years ago 7:12am 7 February 2023 - π§πͺBelgium weseze
This will not fix the issue, it will just create more difficult to debug issues...
It is perfectly fine to create media entities in a non-default language and add translation to the default language.We should check if the entity is the original translation as suggested by @larowlan
- πΊπΈUnited States jumpsuitgreen
Thanks, @weseze. Regarding the "β¦more difficult debug issues" are those caused by the reversing of the conditions in the if() statement of the submitForm()? The only thing I added happens in the buildForm() function of the MediaDeleteForm classβit checks if the media item being deleted is in the default language. If not, the option to delete the related file when deleting the translation is removed. It doesn't prevent the deletion (or creation) of the translated media item itself. If a translated file has been uploaded to the translated media item, its status will be marked as temporary if the translation referencing it has been deleted. Let me know and I'll rework.
- πΊπΈUnited States jumpsuitgreen
@weseze,
In the submitForm() function, I reversed (again) the checks in the if() statement which puts them in their original order. I then wrapped the whole if() block inside a check of the media to ensure it only runs on the default language. When I test locally through the UI, I can- create a new media item in default language
- add a translation of the media entity
- delete the translation the media entity
- create a new translation of the original media entity
- upload a translated file to the translation
- delete the translation which sets the translated file to temporary (since it is no longer is referenced)
- delete the original media entity and associated file
The buildForm() function checks the media to determine if it is the default language and only adds the option to delete the associated file if isDefault() returns true. In short, deleting the associated file is only allowed if the media being deleted is the default language. Translations don't provide the option at all relying instead on trash collection to remove the file since it may be difficult to tell by the name if the file is a translated version or not.
Let me know if this helps, or if I'm still missing something.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Thanks, can we reverse the if and just call the parent and return early, rather than adding another if around the code, less complexity++
We still need a test here too, because this is something that could easily be overlooked in manual testing.
- πΊπΈUnited States jumpsuitgreen
@larowlan
That makes sense. Here is what the code looks like now.buildForm()
Your original code is there but now preceded by a language check of the media entity. If not the default language, it calls the parent form function and returns early.submitForm()
Again, your original code is there but now preceded by a language check of the media entity which returns early if the media entity is not the default language.Here are the local steps I went through for testing:
- Created a new media item in default language
- Created a translation without uploading a translated file
- Deleted the translation
- Created a new translation and uploaded/associated a translated file
- Deleted the translation
- Verified the associated, translated file was demoted to "Temporary" status
- Created a new translation and uploaded/associated a translated file (again)
- Deleted the media item entirely (default language and translation) including the associated file
- Verified the default language file had been deleted
- Verified the second translated file was also demoted to "Temporary" status
Let me know if there are any other manual tests I should run through.
- π¦πΊAustralia larowlan π¦πΊπ.au GMT+10
Thanks, that looks great - can we get a test for this use-case?
When the media's default language is not the site's default language, the checkbox will not be displayed.
- last update
11 months ago 5 pass, 4 fail - π³π±Netherlands MarcKwee
I think we can easily fix this by turning the logic around in the Submit handler.
- π³π±Netherlands MarcKwee
There was a small mistake in my last patch. When you delete the defaultTranslation Media entity. It did not correctly delete the files of the translation media entities, even though those entities will no longer exist.
- π³π±Netherlands MarcKwee
I updated the patch so it also works with the bulk delete functionality.