Hi all.
I got this error when i tried to view unpublished node (with different language)

In the Translation module, in the hook_language_switch_links_alter there is wrong class assignment
in translation.module, line 531
i've just change

$links[$langcode]['attributes']['class'] = 'locale-untranslated';

to

$links[$langcode]['attributes']['class'][] = 'locale-untranslated';
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

c31ck’s picture

Although I'm unable to reproduce the fatal error, the current code in translation.module is indeed not correct. The language switch links get themed by theme_links() and theme_links() expects an array for the class value.

c31ck’s picture

Status: Active » Needs review

Setting status to needs review.

Status: Needs review » Needs work

The last submitted patch, 1408636-translation-attributes-class-array-1.patch, failed testing.

c31ck’s picture

Assigned: Unassigned » c31ck

Tests are probably using the CSS classes. Since attribues['class'] is now an array, some links will get an extra 'language-link' class. I'll look into that.

kafitz’s picture

I have the same problem as described.
I think that Patch 1408636-translation-attributes-class-array-1.patch is a good patch. c31ck has described that the patch failed testing because attributes['class'] is now an array. Following code in translations.test triggers the failures:
$xpath = '//div[contains(@class, :type)]//span[@class="locale-untranslated"]';

swentel’s picture

Status: Needs work » Needs review
FileSize
639 bytes

Trying this one, passes tests locally fine.

c31ck’s picture

Yes, that one will probably pass the tests, but it doesn't respect any classes that have already been set on the link. Is that the behaviour we want here?

swentel’s picture

Hmm, you're right, let me try again locally.

swentel’s picture

FileSize
1.31 KB

Ok, better patch + test fixing

mr.baileys’s picture

+++ b/core/modules/translation/translation.testundefined
@@ -437,7 +437,7 @@ class TranslationTestCase extends DrupalWebTestCase {
+        $xpath = '//div[contains(@class, :type)]//span[@class="language-link locale-untranslated"]';

Since we no longer replace all classes with "locale-untranslated", but rather add it as an additional class, this could still fail if classes other than language-link are added, no?

What about

$xpath = '//div[contains(@class, :type)]//span[contains(@class, "locale-untranslated")]';

-18 days to next Drupal core point release.

swentel’s picture

FileSize
1.31 KB

Absolutely right, better patch.

c31ck’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.27 KB

Looks great. Setting to RTBC based on #5, #10 and my own review.
Adding a D7 patch.

Dries’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I agree that this is a bug. Committed to 8.x. Moving to 7.x for backporting.

c31ck’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.27 KB

Patch for D7.

Rar9’s picture

Patch #14 also works for 7.12 :-)

C. Lee’s picture

Status: Needs review » Reviewed & tested by the community

#14 works. Considering the simplicity of the patch, it seems safe to mark it as reviewed.

vasike’s picture

i can confirm both : the bug and the solution #14.

webflo’s picture

#14 works fine. Please commit this patch. Related issue in i18n issue queue: #1406594: Fatal error: [] operator not supported for strings in includes/common.inc on line 2320.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 7.x. Thanks!

xjm’s picture

batigol’s picture

Thx guys ! A hour ago this error hit me. Good to know it's ALREADY fixed :)

Status: Fixed » Closed (fixed)

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

husumiao-1’s picture

It's cool. 1408636-9.patch is worked.

gunwald’s picture

I get the same error on all user pages for anonymous users:
»user«,
»user/register«, etc

I applied the patch in #14, but this patch did not solve my problem completely. Know the »user« site seems to work but not the other sites like »user/register« etc.

I do not get any further reports (on admin/reports/dblog). Don't know how to debug. What could I do?

post scriptum: Know I figured out, that the issue's cause are these lines in one of my custom modules:

    $account = l(t('Login'), 'user/login',          array('attributes' => array('class' => 'light login')));
    $login      = l(t('Register'), 'user/register', array('attributes' => array('class' => 'light register')));

The link creation is wrong, must be:


    $account = l(t('Login'), 'user/login',     array('attributes' => array('class' => array('light account'))));
    $login = l(t('Register'), 'user/register', array('attributes' => array('class' => array('light logout'))));

I'am sorry to bother you, was my fault!