The problem:
Creating a translation for some node with some fields (even the default fields like image for article), results in adding this field even if it's empty (e.g. you didn't upload a new image for the translated node). When you go to the home page you'll get a huge image's module path error, because it's trying to get a path for a null field. This case for image field, other fields also resulting in the same problem, but the most visible one is the image huge error.
Reproduce:
Install translation, enable some addtional language, then add a node, translate it and just don't add a value for an image field. Go back to the homepage now, you'll see a huge image's module error with a page without css styles too.
Patch in first comment, don't know if it's the best approach, but I'm removing any field that is not translated (has no value). Feedback?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | untranslated-fields_4.patch | 1.82 KB | good_man |
| #5 | untranslated-fields_3.patch | 1.54 KB | good_man |
| #4 | untranslated-fields_2.patch | 1.52 KB | good_man |
| #1 | untranslated-fields.patch | 2.08 KB | good_man |
Comments
Comment #1
good_man commentedComment #2
sunLacking any docs, it's not clear to me what this form validation handler is actually doing.
Tabs all over the place in this patch :-/
Not all fields have a 'value' column.
Why is this check limited to $delta 0 ? If I'm not mistaken, deltas don't necessarily have to start at 0.
Powered by Dreditor.
Comment #3
good_man commentedwell what I was thinking is when we do submit, we can handle the empty fields in validation function, and try to remove them or make them null if that is the right thing to do. I don't know if there is a better approach.
I just looked at the way node module is handling empty fields, you'll get an empty array of this field (e.g. ['field_name']['lang_code'] is empty).
Comment #4
good_man commentedThis issue also affects multi-value fields, I tried to validate all fields before submitting them, and passing them to setTranslation(). This issue doesn't appear in node's submit (without translation, e.g. add new article), because node's submit validate all fields and remove the empty ones, haven't found it in node's module to use here, so I tried to remove them manually.
Comment #5
good_man commentedUpdated patch against the current head, this is an important one, could we have it in next release?
Comment #6
plachWe cannot address this problem in a field-specific way: we probably should be using
field_attach_form_validate()andfield_attach_submit()to filter out empty values and validate form widgets.Comment #7
good_man commentedI didn't get what you mean by field-specific way, but as I can tell from testing that neither the default attach_form_validate() nor field_attach_validate() can address this problem because of one thing, that they rely on 'language' index inside entity which we have it always set to original language (because we have field based translation, not entity based), that's why the default validate fails to get the language and iterate through it.
I'll try to use field_attach_validate hook to do our custom validation and iterate through all possible languages inside form values.
Comment #8
good_man commentedHere is a rework of the previous patch, can't get the field_attach_validate to do the job in hook like:
so I put the logic inside the validation callback.
I've tried almost all the possible ways to do so, and checked how node & fields ui do the validation also, as I said in the previous comment our problem is language inside entity only set to source language that's why default validation fails to detect translated fields.
Comment #9
good_man commentedComment #10
plachMoving to the Entity Translation queue. Read #902760: Change module name so it can work with Core translation for details.
Comment #11
plach#1098106: Translated fields aren't validated (or processed with presave and submit field_attach_ hooks) has a RTBC patch that should fix this issue. Please move there and confirm.
Comment #12
plachComment #13
plach