Check if t($string) is empty before calling locale()

beholder - March 20, 2008 - 16:04
Project:Drupal
Version:6.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

When I've added field of types Text Field or Text Area to form. When 'Help text' of this field is empty, there is label 'Array' instead of description under textfield.

I go to function text_textfield_process() and insert code: print_r($element);die(); on the beginning of the function. Then I goto /node/add/page and see that variable $element contains HUGE (about 2000 strings) array on the [#description] element instead of empty string:

Array
(
    [#type] => text_textfield
    [#default_value] => Array
        (
            [value] =>
        )

    [#field_name] => field_comission
    [#title] => Комиссия
    [#description] => Array
        (
            [ru] => Array
                (
                    [Advanced options] => Дополнительные настройки
                    [Save configuration] => Сохранить настройки
                    [Page not found] => Страница не найдена
                    [Access denied] => Доступ запрещен
                    [You are not authorized to access this page.] => Зарегистрируйтесь, чтобы получить доступ к этой странице.
                    [%message in %file on line %line.] => %message в файле %file в строке %line.
                    ...
                    ...

It seems that this array contains all russian strings from my site. I have two languages on site and i18n module. I can't find where function text_textfield_process() is called and where $element variable is filled.

When Help text filled with text, everything is allright - description show this string.

#1

KarenS - March 27, 2008 - 01:37
Project:Content Construction Kit (CCK)» Internationalization
Version:6.x-1.x-dev» 6.x-1.x-dev
Component:text.module» Code

CCK does nothing unusual here -- it creates a normal form element with #description that may or may not have some text in it. From your explanation it sounds like it works OK if there is text there, but not if it is empty. I suspect this is some i18n issue that happens when #description in a form element is empty, so I'm moving it there so someone who knows how that module works can investigate it.

#2

beholder - March 27, 2008 - 12:48
Project:Internationalization» Content Construction Kit (CCK)
Version:6.x-1.x-dev» 6.x-1.x-dev
Component:Code» text.module

No, this problem is not i18n module bug.
I have made clean install of the Drupal 6.1 and CCK 6.x-1.x-dev version. Then I add textfield with empty description - everything was fine. But then, I turn on core 'Locale' module, add Russian language and make it default. Then 'Array' again appear instead of description under textfield. So this is CCK problem.

#3

KarenS - March 28, 2008 - 11:12
Project:Content Construction Kit (CCK)» Internationalization
Version:6.x-1.x-dev» 6.x-1.x-dev
Component:text.module» Code

Or the problem could be in the Locale module. If you insist on moving this to the CCK issue queue it is not going to get any attention for a while because it involves installing the Internationalization package so I can test if my idea of the problem is right.

I think there may be a bug in that package that is using isset() to test whether the $form #description needs to be filled in instead of checking empty(). If so, it will affect any $form that has an empty #description.

Moving it back so someone can test that theory out.

#4

beholder - March 28, 2008 - 12:03

Why you always point to Internationalization module? As I said, in second comment, now I have a _clean_ install of the Drupal 6.1 - without i18n package. There only core modules (Locale is one of them) and CCK. And this bug is arrive. You could recreate this situation - just add another language and make it dafault.
Again, this is not 18n package bug. Maybe Local module - I don't know. But Locale is core module.

#5

KarenS - March 28, 2008 - 13:37
Project:Internationalization» Drupal
Version:6.x-1.x-dev» 6.x-dev
Component:Code» locale.module

OK, right, moving to Locale.

I think I see where this is coming from in the locale module, on line 332 there is a line:

<?php
if (!isset($string)) {
?>

I think that should be:

<?php
if (empty($string)) {
?>

#6

Damien Tournoud - March 28, 2008 - 13:50
Component:locale.module» base system

The problem is in fact that t() is called with a NULL value. The bug is that t() pass that value directly to locale(). It should not do that, because locale() returns all strings when it is called with a NULL value (as described in http://api.drupal.org/api/function/locale/6).

#7

andershal - May 24, 2008 - 17:59
Title:Textfield description bug» Check if t($string) is empty before calling locale()

The t() function should check the value of string before calling locale. Maybe as one of the first lines:

if (empty($string)) {
  return $string;
}

 
 

Drupal is a registered trademark of Dries Buytaert.