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?

Comments

good_man’s picture

StatusFileSize
new2.08 KB
sun’s picture

Status: Active » Needs work
+++ translation.admin.inc	15 Dec 2010 17:25:02 -0000
@@ -344,6 +346,21 @@ function _translation_form_language(&$it
+function translation_edit_form_validate($form, &$form_state) {
...
+  foreach ($form_state['values'] as $field_name => $field) {

Lacking any docs, it's not clear to me what this form validation handler is actually doing.

+++ translation.admin.inc	15 Dec 2010 17:25:02 -0000
@@ -344,6 +346,21 @@ function _translation_form_language(&$it
+	if (isset($item['fid']) && empty($item['fid'])) {

Tabs all over the place in this patch :-/

+++ translation.admin.inc	15 Dec 2010 17:25:02 -0000
@@ -344,6 +346,21 @@ function _translation_form_language(&$it
+	  $form_state['values'][$field_name][$langcode][$key]['value'] = '';

Not all fields have a 'value' column.

+++ includes/translation.handler.inc	15 Dec 2010 17:25:02 -0000
@@ -312,7 +312,9 @@ class TranslationDefaultHandler implemen
+	  if (!empty($values[$field_name][$langcode][0]['value'])) {

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.

good_man’s picture

well 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).

good_man’s picture

Status: Needs work » Needs review
StatusFileSize
new1.52 KB

This 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.

good_man’s picture

StatusFileSize
new1.54 KB

Updated patch against the current head, this is an important one, could we have it in next release?

plach’s picture

Status: Needs review » Needs work

We cannot address this problem in a field-specific way: we probably should be using field_attach_form_validate() and field_attach_submit() to filter out empty values and validate form widgets.

good_man’s picture

I 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.

good_man’s picture

StatusFileSize
new1.82 KB

Here is a rework of the previous patch, can't get the field_attach_validate to do the job in hook like:

translation_field_attach_validate($entity_type, $entity) {
...
}

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.

good_man’s picture

Status: Needs work » Needs review
plach’s picture

Project: Content translation » Entity Translation
Version: 7.x-2.x-dev » 7.x-1.x-dev
plach’s picture

#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.

plach’s picture

Status: Needs review » Postponed (maintainer needs more info)
plach’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.