When using Entity Translation, in a node that has a specific language but no translatable fields, the specified meta tags are ignored.

There is indeed a check for existing translatable fields in the entity, that makes this to happen:

foreach (field_language($entity_type, $entity) as $field => $lang) {
  // Only accept actual language values that are properly enabled.
  if ($lang != LANGUAGE_NONE && in_array($lang, $enabled_languages)) {
    $langcode = $lang;
  }
}

Steps to reproduce:

  1. enable Entity translation and Metatag modules,
  2. add an extra language,
  3. enable "node" support in Entity Translation settings,
  4. create a new content type that uses Field translation (do not add any field),
  5. create a new content, using custom meta title and specifying a language (no language neutral),
  6. save the nod

e.

What we see:
The meta title is the one created by the default token

What we should see:
Our custom meta title

Files: 
CommentFileSizeAuthor
#15 metatag-custom-metatags-are-ignored-with-entity-translationand-panels-2056739-15.patch609 bytesB-Prod
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#13 metatag-custom-metatags-are-ignored-with-entity-translationand-panels-2056739-13.patch609 bytesB-Prod
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#5 metatag-n2056739-5.patch496 bytesDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#1 metatag-custom-metatags-are-ignored-when-using-entity-translation-2056739-1.patch541 bytesB-Prod
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

Comments

B-Prod’s picture

Status:Active» Needs review
StatusFileSize
new541 bytes
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

I actually do not understand the full purpose of the part of code quoted above, but there is certainly a reason for that and I would be glad to know it.

So I didn't modify it and just add a condition check before. But I am not fully convinced by the current patch, because I have a lack of knowledge on this part of code.

But note that the metatag_entity_update() function uses the metatag_entity_get_language($entity_type, $entity) function to get the language for which are saves the metatags. So the suggested patch just complies with this, no more.

DamienMcKenna’s picture

This is a duplicate of #2140449: Metatags broken for nodes in different languages. I'll pick one but mention both in the commit message.

DamienMcKenna’s picture

Can you please confirm the problem still exists in the current -dev release?

DamienMcKenna’s picture

Marked #2140449: Metatags broken for nodes in different languages as a duplicate, though it does have a patch from zhuber.

DamienMcKenna’s picture

Issue summary:View changes
StatusFileSize
new496 bytes
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

Does this solve the bug too?

DamienMcKenna’s picture

Status:Needs review» Closed (cannot reproduce)

I could not reproduce this problem with the current -dev release.

hideaway’s picture

Hello there. I have exactly the same problem with Metatag module (latest or dev). Our metatags are completely ignored. We use multilingual site where almost everything is translated - content/taxonomy/fields/strings, but surprisingly NOT entity translation. For me the patch from #5 solved everything, can we get it commited as well?

hideaway’s picture

I found out that this happen only for content types which are rendered through panels. When showing node for content type which is not in panels (it does not have variant defined in panels under page node/%node), everything is OK.

And I also found out (compared to clean installation with panels, where it works), that in my case, after editing content, I get stored content's language to metatag table ('fr'/'en'). In the fresh installation there is always 'und' and therefore in metatag_metatags_view you get metatags extracted, since you pass the condition on first elseif:

    // Get the display language; default to the entity's language.
    if (isset($options['language']) && isset($options['language']->language) && isset($metatags[$options['language']->language])) {
      $metatags = $metatags[$options['language']->language];
    }
    // If no language requested, use the no-language value.
    elseif (!empty($metatags[LANGUAGE_NONE])) {
      $metatags = $metatags[LANGUAGE_NONE];
    }
    else {
      $metatags = array();
    }

Consolusion, this BUG is side effect by translation modules (Content translation/Entity translation), since they store language to metatag table as well. Can we get at least that failover #5 patch commited?

hideaway’s picture

Last one from me. Full repro steps:
1. Install Metatags, Panels, Page manager and Locale module
2. Create variant for page 'node/%node'
3. Create any content, fill the metatags.
4. Your metatags wont show up

Conclusion:
With this conditions, you get stored 'en' language to the metatag table:

node 2 2 en BLOB

And you're done, since metatag module is detecting this improperly and your metatags get stripped, since they don't pass conditions in metatag_metatags_view():

    // Get the display language; default to the entity's language.
    if (isset($options['language']) && isset($options['language']->language) && isset($metatags[$options['language']->language])) {
      $metatags = $metatags[$options['language']->language];
    }
    // If no language requested, use the no-language value.
    elseif (!empty($metatags[LANGUAGE_NONE])) {
      $metatags = $metatags[LANGUAGE_NONE];
    }
    else {
      $metatags = array();
    }

You can cry your eyes out.

hideaway’s picture

Status:Closed (cannot reproduce)» Active
hideaway’s picture

I tried both fresh version and then with enabling Content translation and the following change in metatag_ctools_render_alter() seems solved everything:

metatag_entity_view($entity, $entity_name, 'full', NULL, TRUE);
->
metatag_entity_view($entity, $entity_name, 'full', $entity->language, TRUE);

PS: sry that I don't know how to create patches (yet).

B-Prod’s picture

@hideaway: not sure we could rely on the "language" property for any entity. I will investigate on this then provide a patch.

B-Prod’s picture

Status:Active» Needs review
StatusFileSize
new609 bytes
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

@hideaway: could you test the patch above?

Sadly, I am not currently able to perform tests on my original configuration...

hideaway’s picture

Hello,

Tested, but it does not work. Problem with #13 patch is that you are calling entity_language with array and it is expecting string ('node', 'user') so it will return NULL with additional warning. If I changed the code to the following, everything worked:

$langcode = entity_language($entity_name, $entity);
metatag_entity_view($entity, $entity_name, 'full', $langcode, TRUE);

And I corrected my repro steps above. Locale module is enough for reproducing (it does not require Content translation), since Locale starts putting entity language to the metatag table instead of 'und'.

B-Prod’s picture

StatusFileSize
new609 bytes
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

@hideaway: thanks for your feedback!

I updated the patch as you suggested. If it applies successfully and fixes the issue, please set this issue as RTBC.

Blackice2999’s picture

Hi,

i think this is not the correct way to resolv this only for panels. The same issue happens on alle full pages where entity will be visible in other language.
See: #2185791: Wrong metatag used when viewing a node with a language that is not current site language

bojan_dev’s picture

Status:Needs review» Reviewed & tested by the community

I have tested patch #15, and works fine for me.

Blackice2999’s picture

Hi,

i am sorry for confusion. This patch seems to be need also. It resolves it on multilanguage nodes but #2185791: Wrong metatag used when viewing a node with a language that is not current site language keeps (independent bug from this one)

Patch #15 tested and works for me.

  • Commit 3841a2a on 7.x-1.x authored by B-Prod, committed by DamienMcKenna:
    Issue #2056739 by B-Prod: Incorrect language handling when displaying...
DamienMcKenna’s picture

Status:Reviewed & tested by the community» Fixed

Committed. Thanks for pushing this one.

DamienMcKenna’s picture

Could someone please give #2186241: Incorrect metatags for node revisions in panels a review too, it's related. Thanks.

B-Prod’s picture

@DamienMcKenna: done :-)

Status:Fixed» Closed (fixed)

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