Empty Sitemaps if Content language access module is enabled.

Created on 17 February 2023, over 2 years ago
Updated 8 March 2024, about 1 year ago

Problem/Motivation

Hi! We are running a Drupal 9 multilanguage with module Content Language Access enabled to prevent users to view content different from the current's language site.

We've used XMLSitemap to create a Sitemap per language/domain:

domain.com/sitemap.xml
es.domain.com/sitemap.xml
it.domain.com/sitemap.xml
fr.domain.com/sitemap.xml
...

The problem presents while generating the content through all the sitemaps. At some point in class, XmlSitemapLinkStorage there's an well & expected check access for the annonymous user: $entity->access('view', $annonymous) so, the content different from the current's language site is denied, so the link is discarded from the sitemap.

The result is you have domain.com/sitemap.xml with the content and the others domains get their sitemaps empty, with just their headers.

Proposed resolution

Since we can't bypass the content language access permission for annonymous (it's not an option for us) we thought of switching the current language during the process. We implemented a language negotiator to do so, based on this answer. https://drupal.stackexchange.com/a/216051

I've made a patch what works just fine for us, maybe someone finds this useful. All suggestions are very welcome too!

💬 Support request
Status

Needs work

Version

1.4

Component

Code

Created by

🇪🇸Spain missvengerberg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024