I have site, where main language is russian and user can't select answer as best answer. I tried to debug it and what I see in the question_answer.pages.inc

$node->{$qtype[$node->type]['answer']}[$node->language][0]['value'] = ($action == 'deselect') ? NULL : $cid;

if I print_r($node); I see:

    [field_question_best] => Array
        (
            [ru] => Array
                (
                    [0] => Array
                        (
                            [value] => 72
                        )
                )
        )

and after node_save() field is still empty. If I add value manually through the node edit form and print_r($node); i see

    [field_question_best] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [value] => 72
                        )
                )
        )

So this field have no language. And when I change row to
$node->{$qtype[$node->type]['answer']}[LANGUAGE_NONE][0]['value'] = ($action == 'deselect') ? NULL : $cid;

everything works like a charm.

May be numeric field is not translatable, so we need everywhere in a module use LANGUAGE_NONE instead of $node->language?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcisio’s picture

May be numeric field is not translatable, so we need everywhere in a module use LANGUAGE_NONE instead of $node->language?

That could be it. If we found somewhere when a numeric field is marked translatable = FALSE (or a text field with translatable = TRUE), I'll be comfortable to change that code. I searched in the field and locale modules but did not find it ;(

Cray Flatline’s picture

I'm not sure but I think we have to look field settings in the field_config table. We need to get row for our field and look for value of "translatable". If it is set to 1 - we should use $node->language. Otherwise, we should use LANGUAGE_NONE.

I will try to debug it on a dev environment, but it is not so easy for me, because my drupal kung-fu is not so strong :)

Cray Flatline’s picture

I can try to fix it using field_info_field($field_name) to retrieve field info, but I'm not sure I'm enough to correctly create a patch. Or it's better if you make it by yourself?

Cray Flatline’s picture

I've created patch for this issue. Please review it, because It's my first patch ;)

I've tested it on my local environment, it works correctly.

jcisio’s picture

Status: Active » Needs review

There were a few locale support changes in the last Drupal 7 minor releases. We should check it with the last release.

Maks’s picture

After applying this patch I had a lot of errors: Notice: Undefined index: rubrics в функции question_answer_preprocess() (строка 187 в файле /home/****/****/*****/sites/all/modules/question_answer/question_answer.module).
"rubrics" - the machine name of the content type, but this bug is present with all content types
--------
У меня не важный английский, поэтому повторю на русском.
После применения патча, постоянно куча ошибок в Журнале: Notice: Undefined index: rubrics в функции question_answer_preprocess() (строка 187 в файле /home/****/****/*****/sites/all/modules/question_answer/question_answer.module).
В данном случае указана ошибка с типом Рубрики, но это происходит и со всеми остальными типами.
Также, не понятно что именно должно выводиться, как выбранный комментарий: Сам комментарий или только ссылка на него? У меня выводится Имя и Дата, как ссылка на сам комментарий.
С уважением,

jcisio’s picture

Status: Needs review » Needs work
vpiotr’s picture

Status: Needs work » Patch (to be ported)
FileSize
1.42 KB
700 bytes

Quick workaround:

There is a problem with saving field to database using a selected (not unknown / default) node language.
I don't know why, but in the attachment you can find workaround.

1) Patch question_answer.pages.inc to save "selected answer" field using "undefined" language.

2) Patch question_answer.module to load "selected answer"
a) using selected language and if not found:
b) using "undefined language"

This patch will work even when saving in selected language will be fixed.

vpiotr’s picture

FileSize
1.62 KB

A more safe version of my patch in attachment (use it instead of my previous patch for file "question_answer.module").

jcisio’s picture

Status: Patch (to be ported) » Needs work

A hunk in the .pages.inc file in #8 was missing in #9. Also coding standards are not respected.

jcisio’s picture

Issue summary: View changes

fixed some typo