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

Command icon 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:

Comments

kiseleva.t created an issue. See original summary.

kiseleva.t’s picture

kiseleva.t’s picture

Assigned: kiseleva.t » Unassigned
Status: Needs work » Needs review

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mfb’s picture

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

mfb’s picture

Version: 9.2.x-dev » 9.4.x-dev
Issue tags: +Needs tests

Moving to current branch and adding "Needs tests" tag

mfb’s picture

Status: Needs review » Needs work

Ok, I noticed a couple problems with this MR, so setting to needs work.

  1. The logic is wrong, such that hreflang tags for translations aren't added - this is reflected in the test failures.
  2. The hreflang tags are cached, without query string as a cache context. As a result, cached hreflang tags will end up being present even if the logic here says they should not be added.

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.

mfb’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.47 KB

Here's a take on #9 - adding query string to the hreflang tags.

Status: Needs review » Needs work
mfb’s picture

Status: Needs work » Needs review
StatusFileSize
new5.87 KB

Changing some more test expectations for the new cache context

mfb’s picture

The 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?

mfb’s picture

Issue summary: View changes

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Not sure how often accessibility meets.

But there are two proposed solutions can it be highlighted which was chosen please.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mytungsten’s picture

One 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=17 of the US site?

mfb’s picture

Status: Needs work » Needs review

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

mfb’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Needs work

Reading the 2 options like the idea of using lazy builder too. Moving to NW for that patch.

paucala’s picture

Hi 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?

aerzas’s picture

Re-rolled patch #14 against Drupal 10.2.3

_pratik_’s picture

Version: 11.x-dev » 10.2.x-dev
Status: Needs work » Needs review

#27 seems working for 10.2.10 . Need to check if it pass test cases.

ramprassad made their first commit to this issue’s fork.

smustgrave’s picture

Version: 10.2.x-dev » 11.x-dev
Status: Needs review » Needs work

ramprassad’s picture

Assigned: Unassigned » ramprassad

ramprassad changed the visibility of the branch 3226887-hreflang to hidden.

ramprassad’s picture

Created a MR(10476) with the changes for 11.x. Please check

ramprassad’s picture

Assigned: ramprassad » Unassigned
Status: Needs work » Needs review
mfb’s picture

Status: Needs review » Needs work

Hmm, 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.

carlitus’s picture

I cannot apply the MR for d11.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.