When CCK field or field group descriptions are empty, the following error is showing up:

warning: preg_match() expects parameter 2 to be string, array given in includes\bootstrap.inc on line 775.

It appears that when the string is empty the t() function returns an Array? Here are some of the places that are causing the issue that I've found by dumping the back trace from the bootstrap method:

fieldgroup.module#537

            '#description' => $label ? content_filter_xss(t($group['settings']['display']['description'])) : '',

content.node_form.inc#101

        $description = content_filter_xss(t($field['widget']['description']));

Comments

yched’s picture

Category: bug » support

Cannot reproduce. That would be a major bug which would have raised 100's of reports :-)
t('') return ''.

I'm not sure what is happening on your setup. Looks like $field['widget']['description'] and $group['settings']['display']['description'] are returning arrays instead of strings.
A couple suggestions in the dark :
- re-save your fields and groups
- empty your site's cache (admin/settings/performance, 'Cleard cached data' at the bottom of the form)

Also, are those fields coming from an upgraded D5 setup, or were they created in D6 ?

ahansen1’s picture

I just double checked and t() does return an Array on null on my setup? I just put the following in a page:

<?php print t(null) ?>

And the output is:

Array

This is from a migrated setup. However, I deleted all of the directories except for sites and files before plunking in the 6.10 install. I have seen this error come up on various module forums. I'm not sure why my setup is returning that? I guess you're saying it shouldn't be and isn't on yours.

ahansen1’s picture

So, I dug a little deeper and found something interesting. As I mentioned t(null) was returning an array. This seems to be because of the following snippet in common.inc:

  if (isset($custom_strings[$langcode][$string])) {
    $string = $custom_strings[$langcode][$string];
  }

It seems that in my environment $custom_strings[$langcode][$string] was equal to:

Array ( [] => Array ( [] => ) )

So, naturally when $string was null it returned the empty Array. I worked around the issue by putting the following snippet in my settings.php file:

 $conf['locale_custom_strings_en'] = array(
   'somevaluethatshouldneverbehit'      => '',
  );

Now everything seems to be fine and dandy. Should the value of $custom_strings[$langcode][$string] not have been what it was in my environment? Is this a core bug? Or do you think something is just funky in my environment?

jonathanhuot’s picture

I had the same issue, but the following was printed as an error instead of yours :

drupal warning: strlen() expects parameter 1 to be string, array given in (..)/bootstrap.inc on line 892.

In my case, strlen was called by content_filter_xss no matter t returned an array.
Only one fieldgroup had this issue, and I edit-it/submit blank description to fix it.

Why none description was inserted in database ? well... module code just call these fews lines of CCK API code :

$group = array('group_type' => 'standard', 'label' => 'Costs', 'group_name' => 'group_merci_pricing', 'weight'  => -3, 'settings' => array('form' => array('style' => 'fieldset')));
  
fieldgroup_save_group('merci_reservation', $group);

Maybe CCK should set a blank description if none was given in function call ?

jonathanhuot’s picture

Version: 6.x-2.x-dev » 6.x-2.9
Component: General » fieldgroup.module

Updated issue fields.

Syg’s picture

The fact is that you should avoid to use variables in t() function or at least verify that your variable is not NULL.

From API :

The only case in which variables can be passed safely through t() is when code-based versions of the same strings will be passed through t() (or otherwise extracted) elsewhere.

For information, I added those lines till the bug is fixed :

  if($group['settings']['display']['description']) {
    $group_display_desc_translated = t($group['settings']['display']['description']);
  } else {
    $group_display_desc_translated = $group['settings']['display']['description'];
  }

  $element = array(
    '#title' => $label ? check_plain(t($group['label'])) : '',
    '#description' => $label ? content_filter_xss($group_display_desc_translated) : '',
  );

Edit :
My problem was that features exported a NULL value for some fieldgroup descriptions. So re-entering an empty string ('') in the description fixed the issue.