2

I have a custom field that contains a managed file. The node that the field is attached to and the field are enabled for translation.

I create a piece of content, which defaults to the site default language EN. The content contains a managed file, let's say FID 1.

From the admin content screen I select Translate and add a translation. When the node edit form is rendered, it contains the values from the original content as it should, and contains the file information as well, so that I need to remove the original and add a new one.

When I save this version, language ES, both appear on the admin page and in the db. The property for the managed file in ES has FID 2.

The issue is when switching back to English using the language widget on the home page, a 500 is received. The reason is that removing the managed file from the Spanish translation in order to add the correct one resulted in the actual file being removed as well as the FID 1 file_managed table entry, but 1 still remaining in the property value for the managed file in the custom field.

I could probably finagle the custom field widget to not present a default value for the managed file property somehow in the case of adding the node, but that seems wrong, because it's possible that the user to leave the file the same.

Is there a standard way to handle this?

2
  • Just FYI D8 managed file ref counting has issues, see #2821423 for an overview. Maybe the specific issue you're having is 2810355?
    – Andy
    Jun 27, 2018 at 9:09
  • Yup, that’s it, exactly! Can you add it as an answer or refer to it in one so I can select it? For now, I think I’ll have to try and handle it by hooking and removing the file reference from the translation node form or if possible hook its removal and bypass the mechanics.
    – JAyenGreen
    Jun 27, 2018 at 13:38

1 Answer 1

1

There are a number of issues with reference counting files: see this overview. You might be affected by $entity->isDefaultTranslation() behaves incorrectly when changing default translation, causing file/image field usage to be set to zero, causing files to be deleted.

Note that due to the potential for lost data, as of 8.4 the default behaviour has been changed to not delete files even if their ref count reaches zero. See the CR for more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.