Problem/Motivation

We noticed that the language selection labels changed in one of our projects to the default language, instead of the current interface language.

A lot of debugging later, we tracked it down to #3080314: Load metatag defaults based on entity language. In our case, the entity has a fixed default language (german), so when adding content in english, that function set the config override language to german and any config that is loaded afterwards then displays in german.

Proposed resolution

Restore the current config language at the end of the function

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

Berdir created an issue. See original summary.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new779 bytes
berdir’s picture

Ok, that second check doesn't work because entity has been loaded from the route at that point. This should be better.

berdir’s picture

I didn't test it, but I'm pretty certain that's a very different issue. That is about the language used in the token replace call, this is about the config override language.

spadxiii’s picture

StatusFileSize
new1.14 KB
new350 bytes

Ran into this issue myself as well and after a bit of debugging and searching, found this issue. The patch seems to fix the issue for me, and I've restored the config override language on the other return in the function.

berdir’s picture

Oh, nice catch on no defaults. Wondering if we could just do it directly after the getGlobalMetatags() call then we only need to do it once?

spadxiii’s picture

It might seem that it could be reset after grabbing the global meta tags. I cannot oversee the things that are done in the rest of the method and whether or not they would need to have the correct language set as well.

So, I'm for doing it only once, but cannot tell for sure if that would work properly :)
(And not exactly sure how to actually verify that it works)

damienmckenna’s picture

Issue tags: +Needs tests

So for test coverage, loading an entity form in a non-default language should trigger the problem, right?

berdir’s picture

To reproduce, you need o have a site with at least 2 languages and have translations for configuration on that page, e.g. the language labels.

Then the entity bundle needs to be configured to use the default language for new entities, then you need to go to node/add/page on a not-the-default-language, and as a result, you should see that first, the page should use the not-default-language translations (e.g. the node type name), and then after calling the metatag widget, it switches (languages can be used as an example for this because they are rendered in a pre_render callback later on).

damienmckenna’s picture

Status: Needs review » Needs work

This needs test coverage before we commit it, just to be sure.

berdir’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.75 KB
new3.89 KB

Fair, but that's quite a bit of work because I don't think getting config translations like that is tested at all, the existing test coverage seems to be testing just the basic UI operations of config translations, which means the only thing all of that is testing is really just the correct config schema definitions.

Anyway, I decided to implement something by using the API directly instead of going through the form, which would require a lot more setup including several config translations of elements before and after the metatags in the form. To make that work, I also had to change the language-creation to use the API otherwise it doesn't exist in the test container. But IMHO that's common practice, there's no benefit in doing it through the UI and this is a lot faster as the UI is doing quite a few extra things ( a full localize.drupal.org import is luckily disabled by default in tests now).

As a bonus to make up for that, I also added explicit test coverage of that early return. My patch in #3 fails with this test.

The last submitted patch, 12: metatag-default-config-3108052-12-test-only.patch, failed testing. View results

  • DamienMcKenna committed 28c317d on 8.x-1.x authored by Berdir
    Issue #3108052 by Berdir, SpadXIII: metatag_get_default_tags() does not...
damienmckenna’s picture

Status: Needs review » Fixed
Parent issue: » #3164682: Plan for Metatag 8.x-1.15

Thank you both for your work on this. Committed.

Status: Fixed » Closed (fixed)

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