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.

Files: 
CommentFileSizeAuthor
#11 metatag-caching_multilingual_content-2025425-11-BETA7.patch619 bytesDavid_Rothstein
#10 metatag-caching_multilingual_content-1355202-10-BETA7.patch619 bytesDavid_Rothstein
#5 metatag-caching_multilingual_content-1355202-5.patch578 bytesmoonray
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es).
[ View ]
#4 metatag-caching_multilingual_content-1355202-1.patch630 bytesmoonray
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 ]
#2 metatag-caching_multilingual_content-1355202-1.patch683 bytesmoonray
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 ]

Comments

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

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.

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.

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

Trying again.

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.

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)

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().

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).

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.

Same patch, better filename.

Could someone please test the latest dev version?

Component:Code» Multilingual/intl