Hello, I've updated from 1.1 to 1.2 and I've had this error. The error message is:

PHP Fatal error: Unsupported operand types in /home/drupal7/public_html2/sites/translatedweb.com/modules/lang_dropdown/lang_dropdown.module on line 232

I saw the error yesterday after creating a node, the node was created but it wasn't showed. Today I've tried to see the node but I can't, the same error appears in the apache log. Here is the node, it's unpublished and you should be redirected to the login page, but the error happens to me too with the admin account. I've created other content without problems, so I think that it is not a big trouble.

I'm using Drupal 7.12 in Ubuntu Server with Apache2. This is my first bug report in drupal.org, please tell me if you need more information or I've done something wrong.

Kind regards.

Comments

manfer’s picture

I can't see anything wrong in line 232. There is an union of arrays in that line and the operands are arrays so I don't see why you receive an unsupported operand types error.

Line 32

$form += $hidden_elements;

The only thing I can imagine is that $hidden_elements is NULL. But that shouldn't happen ever.

So I only can suggest to debug to try to understand why that's happening. You can just add before that line 232:

debug($languages);
debug($form);
debug($hidden_elements);

And with all that output probably we can try to guess what's happening.

igalarza’s picture

StatusFileSize
new661 bytes
new4.33 KB

Thanks for your fast reply, I've added your debug lines in the module and I've seen this notice in the logs:

Notice: Undefined variable: hidden_elements in lang_dropdown_form() (line 234 of /home/drupal7/public_html2/sites/translatedweb.com/modules/lang_dropdown/lang_dropdown.module).

You was right, hidden_elements is NULL. I've attached the values of the other variables.

Kind regards, and thank you again!

manfer’s picture

I don't understand how you have created that node in a way that all languages claims there is no translation.

      array (
        'class' => 'locale-untranslated',
      ),

so no of them has a href property. I can make a check to just don't show the language switcher at all in that case to avoid that weird problem. Adding this just before line 232:

if ($hidden_elements === NULL) return array();

should resolve that. But you should look why that is happening. What happens on that node if you enable the Drupal core language switcher block?
It seems as if you had created a node with no language but it is not a language neutral node either and I can't understand how you have done that. When you create a node in its language select you can choose one language or the "language neutral" option. There isn't any "no language" option.
The only thing I can imagine is if maybe the node is created with a language and later that language is removed from the list of available languages. Maybe in that case the node falls in that 'no language' state.

manfer’s picture

Ok I think that is the problem, a node in a language that later is disabled or deleted.

The solution is to don't show language switcher at all in that case. Changing line 232:

$form += $hidden_elements;

to:

if (!isset($hidden_elements)) return array();
$form += $hidden_elements;

As a protection to avoid this weird problem that can happen in this case.

But the real solution is reenable the language in which that node is writen if you pretend to use that language.

manfer’s picture

igalarza’s picture

Hello, I've added your code and I can see the node now. However, the node's language is Spanish, and was set to spanish when was created, and this language is enabled in my site since the beggining (is my mother language).

Maybe happened something wrong when I created the node, but now I can see the node, with the spanish language selected.

Thank you again for your help, and kind regards.

igalarza’s picture

StatusFileSize
new1.5 KB
new1.5 KB

More weird things.

I've moved all to my devel enviroment, and I've get the node info using the Devel module (it's attached), after that, I've published the node so you could see it, and now the dropdown is showed!! I don't know what happened but the "broken thing" has been repaired when the node was published.

Then I've unpublished the node, and the dropdown fails again! I'm using a boolean field and rules to publish/unpublish the nodes, could this be related?

Here is the node in the devel env.

Thank you again.

manfer’s picture

Could you edit node just to save it and then debug again the $languages variable to show here its content?

In that variable Spanish should have a href with the node url and language-link as a class in attributes:

    'es' => 
    array (
      'href' => '.../...',
...
...
...
     'attributes' => 
      array (
        'class' => 
        array (
          0 => 'language-link',
        ),
      ),
...
...
...
igalarza’s picture

StatusFileSize
new794 bytes

There are not href nor language-link properties in $languages variable, when the dropdown works and also when it doesn't work. I've attached the output. In both cases the $languages variable is the same.

Regards.

manfer’s picture

I don't know whats wrong with that node that in my opinion has incorrect values in $languages variable.

Can you show your $languages variable in different node? Same debug in language dropdown switcher but in a node in which language switcher works fine.

I'm going to include the check code in language dropdown switcher to avoid this situation but the problem with your node is not related to language dropdown switcher and is really strange.

igalarza’s picture

You are right, the other nodes have the href field:
...
'es' =>
array (
'href' => 'node/19309',
...

I belive that I know what happened. This must be related to pathauto module; when I created the node, I forgot to put the value in one field, a node relationship which is used to create the URL alias:

[node:field-website:title]/[node:title]

After I had added the value the alias was updated, but the error remained. I'm going to delete the node and re-create it, thank you one more time for your fast support. If I see any other thing I will write you.

Kind regards.

manfer’s picture

I'm going to push the following patch to solve this.

manfer’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

botris’s picture

Is this patch committed? If not, it should be RTBC.

brycesenz’s picture

If it helps to clarify what may have been happening, here is how I produced the error:

1. Create a site and enable three languages (English, Spanish, French).
2. Create some nodes, and provide translations in all three languages.
3. Later, disable one of the languages (e.g. German).
4. Try to create a new node, then recieve this error.

The patch seems to fix everything, so +1 on getting this committed.

botris’s picture

Status: Closed (fixed) » Reviewed & tested by the community

Still a bug but patch fixes everything

botris’s picture

Just had a look at the dev it looks like the patch is committed there. No idea when...

manfer’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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