Closed (fixed)
Project:
Hreflang
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 Jun 2018 at 13:41 UTC
Updated:
7 Dec 2018 at 16:05 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mfbInteresting, I've not seen that - the hreflang tags are identical and thus one overwrites the other.
Any chance you could write a failing test to catch this bug or provide steps to reproduce?
Comment #3
eric heydrichThe problem only exists on my frontpage. I've set a node with its own URL as the front node. The core translation modules generate hreflang tags for the node URL. But this hreflang tag is also shown on the front page where there also the hreflang tags for the frontpage which generates multiple links for the same language.
e.g.
Comment #4
mfbok this is caused by the fact that we explicitly set the URL to <front> if we're on the front page:
$route = \Drupal::service('path.matcher')->isFrontPage() ? '<front>' : '<current>';We could remove this line, although this would instruct search engines to index e.g. https://www.domain.com/de/Node-URL rather than https://www.domain.com/de
At the moment what you could do is use hook_page_attachments_alter() to remove the hreflang tags added by core translation module
Comment #5
mfbArguably the
$entity->toUrl('canonical')which is called by content_translation_page_attachments() should be front-page aware, and generate the correct URL when generating the canonical URL for an entity which is the front page? I guess it's a philosophical question, what is the canonical URL anyways? :)Comment #6
mfbFound a related core issue: #1255092: Return "/" instead of the internal path when asked for the URL of the frontpage
Comment #7
mfbComment #8
mfbWell this won't work because module weight is apparently non-deterministic in drupal 8 - based on install time rather than alphabetic. So the content translation hreflang tags may not have been set yet.
Comment #9
Andy_D commentedI've just applied the patch and it generates the following errors:
Notice: Undefined index: html_head_link in hreflang_page_attachments() (line 35 of modules/contrib/hreflang/hreflang.module).Will use the hook instead.
Comment #10
raphaeltbm commentedIt's because content_translation is set with a weight of 10 on the install, so your
hook_page_attachments()will always be run before. You should maybe use something like that to be serene:Else move your code in a
hook_page_attachments_alter()and remove the alternate hreflang generated by content_translation before to proceed with your own module code.By the way, i guess there is no reason to use
html_head_link, you should only usehtml_head. It's recommended to use only 1 method for the alternate hreflang (among the 3 methods: meta html, http header, sitemap xml / see the global SEO recommendations) andhtml_head_linkgenerate meta html + http header.And be aware of these issues:
#2945033: HtmlHeadLink processing does not allow for duplicated alternate hreflang links
>> so the key if you change for
html_head, should be "your-module-name:rel:hreflang:href"#2873648: With many languages, content_translation_page_attachments adds too many alternate links to the response headers crashing varnish (503)
>> one more reason, to only use
html_headfor the alternate hreflang...By the way 2, there is no access checking on the alternate links you are generating (let said that for a page where FR is published but not the EN version, both alternate links (FR + EN (unpublished/403)) will be generated whatever the access rights).
For more info, see #2521782: HTML head has alternate hreflang links to unpublished translations
I will point these problematic later in the core issues too.
Comment #11
mfb@raphaeltbm Thanks for the sleuthing :)
Comment #12
mfbComment #13
raphaeltbm commentedFor info #2994800: Improve the alternate hreflang implementation. Cheers.
Comment #15
mfbComment #16
mfbComment #18
joe huggansThis solution, which is in the latest release did not work for me, for anyone else struggling, this solution worked to remove the duplicates https://www.drupal.org/project/metatag/issues/2993991
Comment #19
mfb@sanskrit I actually added a test for this issue, so if you can write a failing test or provide steps to reproduce that would be helpful.