Problem/Motivation
When Content Translation module adds hreflang link tags to an entity page that is not the canonical URL, e.g. when query arguments are present, the page no longer has the self-referencing hreflang tag that is expected by search engines. I.e. the query string is expected to be appended to the href attribute URL.
Steps to reproduce
I have the node page, which renders a view listing with facets.
When some facet is applied, the canonical is pointed to the original node page.
Hreflang also points to the original node page, it cause the error "No self-referencing hreflang".
Proposed resolution
Option A: Add query arguments to the hreflang link tags, and add query arguments to the cache context. This allows the dynamic page cache to set a unique cache for each set of query arguments.
Option B: To improve cache efficiency, use lazy builder placeholders to add query arguments to the hreflang link tags. At present, HtmlResponseAttachmentsProcessor::processHtmlHeadLink() doesn't really contemplate this; it uses 'html_head_link:...' identifiers (that contain the href attribute) to merge duplicate link tags.
Remaining tasks
Choose one of the proposed solutions. The current patch #14 is Option A (adding cache context); however it seems like a good idea to develop an Option B patch that instead uses lazy builder placeholders for better cache efficiency?
User interface changes
None
API changes
Possibly a sort-of minor API change if link tags use lazy builder placeholders.
Data model changes
None
Issue fork drupal-3226887
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3226887-hreflang-11.x
changes, plain diff MR !10476
- 3226887-hreflang-on-non-canonical-d9
changes, plain diff MR !1013 /
changes, plain diff MR !1012
- 3226887-hreflang-on-non-canonical
changes, plain diff MR !1011
- drupal-3226887-11.x
compare
- 11.x
compare
- 3226887-hreflang
changes, plain diff MR !10475
Comments
Comment #6
kiseleva.t commentedAttached the patch for Drupal 8.9 in case if https://www.drupal.org/files/issues/2020-09-17/problematic_hreflang_link... already applied.
Comment #7
kiseleva.t commentedComment #9
mfbIt seems like a better way to fix this would be for Content Translation module to add whatever query string is present to each hreflang URL.
Analogously, Language module adds
$request->query->all()to each URL in the getLanguageSwitchLinks() method: https://git.drupalcode.org/project/drupal/-/blob/9.4.x/core/modules/lang... and I'd say Content Translation module should have similar code.Comment #10
mfbMoving to current branch and adding "Needs tests" tag
Comment #11
mfbOk, I noticed a couple problems with this MR, so setting to needs work.
Note: Caching would also be at issue with regards to my alternate approach suggested in #9: We'd have to vary the cached hreflang tags per query string.
Comment #12
mfbHere's a take on #9 - adding query string to the hreflang tags.
Comment #14
mfbChanging some more test expectations for the new cache context
Comment #15
mfbThe one unfortunate side effect of adding the url.query_args cache context is extra caches being generated and stored for each set of query arguments used with entity pages. I suppose this could be worked around through the use of lazy builder placeholders for the link tag href attributes?
Comment #16
mfbComment #19
smustgrave commentedComment #20
smustgrave commentedNot sure how often accessibility meets.
But there are two proposed solutions can it be highlighted which was chosen please.
Comment #22
mytungsten commentedOne potential challenge with this would be when not all content is translated across all languages. For example, if on a US site you had 17 pages of articles but on the CA site there were only 5, what would the appropriate hreflang tags be on
?page=17of the US site?Comment #23
mfb@mytungsten That is also a challenge outside of this issue, as if a site uses the built-in language switcher block, then they will get switch links that include such query arguments.
@smustgrave As far as which proposed solution was chosen, option B seemed like a good idea to me for cache efficiency reasons, but there is no patch for option B as of yet. So I'd say this issue probably needs both review to determine a solution, and a new patch/MR to be developed.
Comment #24
mfbComment #25
smustgrave commentedReading the 2 options like the idea of using lazy builder too. Moving to NW for that patch.
Comment #26
paucala commentedHi everyone, I have update to the last version of core (10.2.3) and it seems that the patch does'nt apply anymore. Any idea?
Comment #27
aerzas commentedRe-rolled patch #14 against Drupal 10.2.3
Comment #28
_pratik_#27 seems working for 10.2.10 . Need to check if it pass test cases.
Comment #30
smustgrave commentedComment #33
ramprassad commentedComment #35
ramprassad commentedCreated a MR(10476) with the changes for 11.x. Please check
Comment #36
ramprassad commentedComment #37
mfbHmm, the MR seems to include numerous unrelated changes/fixes? If we decide to go with "Option A" then we would need a cleaner MR (basically just the patch). But in #25 we discussed that we could potentially instead go with "Option B": re-architect hreflang tags to use a lazy builder to add query string to the hreflang links. We don't have a merge request for "Option B" yet.
Comment #38
carlitus commentedI cannot apply the MR for d11.