Multilingual nodes with translated fields don't always output correct language metatags due to caching.

If I view the node in english, the metatags are correct. Then, switching to another language (e.g. French), viewing the same node outputs the english metatags on an otherwise translated page. Only after clearing caches do the correct language metatags appear.

Comments

DamienMcKenna’s picture

What display mechanism are you using for the nodes - Panels, normal page templates, Display Suite, etc?

moonray’s picture

Status:Active» Needs review
StatusFileSize
new683 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-caching_multilingual_content-1355202-1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

The attached patch provides the global langcode by default if none is provided. This way the caching cid is correct.

Status:Needs review» Needs work

The last submitted patch, metatag-caching_multilingual_content-1355202-1.patch, failed testing.

moonray’s picture

Status:Needs work» Needs review
StatusFileSize
new630 bytes
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch metatag-caching_multilingual_content-1355202-1_0.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Same patch with fixed paths.

moonray’s picture

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

Trying again.

DamienMcKenna’s picture

If the current entity doesn't support language assignment, or it's disabled, Metatag uses LANGUAGE_NONE instead of $GLOBALS['language_content']->language, so I don't think this is the best direction.

Also, please clarify what system is being used to display the entity as the $langcode value shouldn't be empty.

moonray’s picture

metatag itself calls the metatag_entity_view() function with the langcode being NULL in 3 instances. These are the cause of the problem.
In my particular case the call from metatag_ctools_render_alter() was the cause of the issue.

The reason I decided to use $GLOBALS['language_content']->language is https://api.drupal.org/api/drupal/modules%21node%21node.module/function/...

EDIT: Also see https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/drup... (which ensures $GLOBALS['language_content'] is always set)

DamienMcKenna’s picture

Status:Needs review» Needs work

Yes, I'm aware of the different reasons to use $GLOBALS['language_content'], however the $langcode value is different in hook_entity_view depending on different scenarios. The reason you're seeing an empty $langcode is because you're displaying the page with Panels, which doesn't work correctly with multiple languages as opposed to normal page displays, so any changes should go into metatag_ctools_render_alter().

moonray’s picture

What about metatag_views_post_render() and metatag_taxonomy_term_view_alter()?

I'm not running through either of those function in my use case. Should those also include the settings of default value for $langcode? (I'd like to provide a full patch).

David_Rothstein’s picture

I ran into this but honestly couldn't figure out how to determine the correct language to pass in for all cases.

I needed something that worked, and if the goal is just to bust the cache when necessary without affecting how the rest of the function uses the $langcode variable, here is one kind-of-hacky way to do it.

Patch applies against the beta7 release, but not against the latest dev code.

David_Rothstein’s picture

Same patch, better filename.

DamienMcKenna’s picture

Could someone please test the latest dev version?

DamienMcKenna’s picture

Component:Code» Multilingual/intl
hefox’s picture

Patch is being used on a project with multiple testers/developers and has not presented any problems yet and has fixed the issue.

Only tested with beta :/

hefox’s picture

beta9 version of beta7

DamienMcKenna’s picture

Status:Needs work» Needs review
StatusFileSize
new1.08 KB
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]

This adds an update script to clear the caches.

DamienMcKenna’s picture

DamienMcKenna’s picture

Status:Needs review» Fixed

Committed. Thanks everyone!

  • DamienMcKenna committed 679c0a1 on 7.x-1.x
    Issue #2025425 by moonray, David_Rothstein, hefox, DamienMckenna: Cache...

Status:Fixed» Closed (fixed)

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