- First commit to issue fork.
- Merge request !76Issue #3302453: Canonical metatag on Views pages no longer refers to current, language page → (Open) created by bbu23
- 🇷🇴Romania bbu23
I've just encountered this issue on some views pages on a multilingual site. I arrived at line 591 in web/modules/contrib/metatag/src/MetatagManager.php file:
// Use the entity's language code, if one is defined. $langcode = NULL; if ($entity) { $langcode = $entity->language()->getId(); }
The language code that is later used in all token replacement calls seems to be declared here, and the $entity variable contains the Views configuration object. This object always returns the default language, at least for my case.
I added a patch that might not be the best fix/approach, but I think it's good to start somewhere. I'm omitting to set the current language if the $entity is a view (probably it applies to all config entities, but idk about that) so that later on in the execution the language is set with the current detected language. We don't want to have the language of the config object, but the interface language (especially for views pages).
I tried the option from comment #10, but that didn't work for me.
- 🇵🇹Portugal introfini
I had the same issue and the current patch fixed it. Thanks.
- Status changed to Needs review
over 2 years ago 5:27pm 24 April 2023 - 🇺🇸United States damienmckenna NH, USA
Setting the status to "needs review" now that there's a merge request to review.
The issue is relevant to webform pages as well. I think it make sense to not extract language from any config entity, not only Views.
- Status changed to Needs work
almost 2 years ago 4:53pm 29 September 2023 - 🇺🇸United States damienmckenna NH, USA
I think it'd be worth improving the test coverage to catch this problem.
- 🇳🇱Netherlands undersound3
FWIW
When I enter [view:url] in the Canonical-URL field under Metatag settings in the view I managed to get a correct url for both languagaes in a multilanguage domain based setup
- Status changed to Needs review
2 months ago 9:47am 11 June 2025 - 🇧🇪Belgium matdemeue
The current patch from #19 didn't fix it for us. In issue #3077442 the generateRawElements function is also updated.
I rerolled it with the same fix in this function as well to cover both cases. This solves the problem in our case where rawElements are used. Review needed.
- First commit to issue fork.
- 🇯🇵Japan aniketto Tokyo
aniketto → changed the visibility of the branch 3302453-canonical-metatag-on-for-2-1 to hidden.
- Merge request !192Issue#3302453: Fix canonical metatags on views. → (Open) created by Unnamed author
- 🇯🇵Japan aniketto Tokyo
aniketto → changed the visibility of the branch 3302453-canonical-metatag-on to hidden.
- 🇯🇵Japan aniketto Tokyo
Patch #21 worked. Attaching before/after screenshots.
Also worked on creating the merge-request for 2.1 branch using the same patch.This issue was picked up as part of Contribution Day Japan 2025 held on 11th July, 2025 at Tokyo.
Below members helped me to confirm the changes and re-create the merge-request.Members: yukihyogo, gengo_k, bassline
- 🇯🇵Japan aniketto Tokyo
aniketto → changed the visibility of the branch 3302453-canonical-metatag-on-2.1 to hidden.
- 🇯🇵Japan aniketto Tokyo
aniketto → changed the visibility of the branch 3302453-canonical-metatag-on to active.
- 🇯🇵Japan aniketto Tokyo
aniketto → changed the visibility of the branch 2.1.x to hidden.