Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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:
- enable Entity translation and Metatag modules,
- add an extra language,
- enable "node" support in Entity Translation settings,
- create a new content type that uses Field translation (do not add any field),
- create a new content, using custom meta title and specifying a language (no language neutral),
- 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
Comments
Comment #1
B-Prod CreditAttribution: B-Prod commentedI 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 themetatag_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.Comment #2
DamienMcKennaThis is a duplicate of #2140449: Metatags broken for nodes in different languages. I'll pick one but mention both in the commit message.
Comment #3
DamienMcKennaCan you please confirm the problem still exists in the current -dev release?
Comment #4
DamienMcKennaMarked #2140449: Metatags broken for nodes in different languages as a duplicate, though it does have a patch from zhuber.
Comment #5
DamienMcKennaDoes this solve the bug too?
Comment #6
DamienMcKennaI could not reproduce this problem with the current -dev release.
Comment #7
hideaway CreditAttribution: hideaway commentedHello 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?
Comment #8
hideaway CreditAttribution: hideaway commentedI 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:
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?
Comment #9
hideaway CreditAttribution: hideaway commentedLast 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:
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():
You can cry your eyes out.
Comment #10
hideaway CreditAttribution: hideaway commentedComment #11
hideaway CreditAttribution: hideaway commentedI tried both fresh version and then with enabling Content translation and the following change in metatag_ctools_render_alter() seems solved everything:
PS: sry that I don't know how to create patches (yet).
Comment #12
B-Prod CreditAttribution: B-Prod commented@hideaway: not sure we could rely on the "language" property for any entity. I will investigate on this then provide a patch.
Comment #13
B-Prod CreditAttribution: B-Prod commented@hideaway: could you test the patch above?
Sadly, I am not currently able to perform tests on my original configuration...
Comment #14
hideaway CreditAttribution: hideaway commentedHello,
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:
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'.
Comment #15
B-Prod CreditAttribution: B-Prod commented@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.
Comment #16
Blackice2999 CreditAttribution: Blackice2999 commentedHi,
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
Comment #17
bojan_dev CreditAttribution: bojan_dev commentedI have tested patch #15, and works fine for me.
Comment #18
Blackice2999 CreditAttribution: Blackice2999 commentedHi,
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.
Comment #20
DamienMcKennaCommitted. Thanks for pushing this one.
Comment #21
DamienMcKennaCould someone please give #2186241: Incorrect metatags for node revisions in panels a review too, it's related. Thanks.
Comment #22
B-Prod CreditAttribution: B-Prod commented@DamienMcKenna: done :-)
Comment #24
marziyeh84 CreditAttribution: marziyeh84 commentedHi,
When i insert my google+ page in Author URL and click save.
Nothing saved and just back to page.
Thanks
Comment #25
Blackice2999 CreditAttribution: Blackice2999 commentedHi, has your issue something to do with this patch? if not please open a new issue instead of hijack this issue. Thanks.
Comment #26
DamienMcKenna@marziyeh84: I'm sorry you're experiencing a problem with the module. However, please don't re-open an issue that was closed two years ago to report a bug. Instead, please just click the "create a new issue" button at the top of the issues page, and then I'll see about helping you.