This issue is for porting the work presently getting done in #1670086: using rel="alternate" rather than multiple sitemaps by language context for D7 in D8.

As that issue hasn't officially been merged yet, I didn't want to cause confusion within that issue by posting the D8 port patch. So I've opted to create a separate issue instead of uploading the patch in there.

If the maintainers prefer though, this can be closed as a duplicate and I can post the patch there instead.

I'm gonna presume additional conversation will need to happen around D8 though.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

WidgetsBurritos created an issue. See original summary.

WidgetsBurritos’s picture

This patch isn't 100% complete... Just wanted to get an initial review to make sure it's generally okay. There are a few services that probably should get injected instead of referencing \Drupal::...

Status: Needs review » Needs work

The last submitted patch, 2: xmlsitemap-using_rel_alternate-2941164-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

manuel.adan’s picture

Such feature is present in the simple_sitemap module. I found it after spent several hours trying to make xmlsitemap run on a multilingual site with no success.

Dave Reid’s picture

Dave Reid’s picture

Issue tags: +Needs backport to D7
Dave Reid’s picture

Status: Needs work » Needs review
FileSize
7.08 KB

I think I can make this work in a backwards compatible way. I can rely implementing hook_xmlsitemap_element_alter() on behalf of content_moderation to inject the alternate links.

We will likely want to get rid of the language context eventually, likely in 2.0, since removing it would mean we need to inspect everyone's sitemap entities again, remove the context and then delete any duplicate sitemap entities.

I would *LOVE* some help testing this out.

Dave Reid’s picture

I also wanted this to work automatically if there is only one sitemap created before the language module was enabled, and so the sitemap entity does not yet have a language context. This should help solve #3006297: When language module is installed, update sitemaps with language context.

Dave Reid’s picture

Dave Reid’s picture

Better version that merges in the default contexts when loading the sitemap entities, instead of using language_xmlsitemap_context_alter(). That will make it compatible with all possible contexts. Still need to figure out what's going on with the test coverage.

Dave Reid’s picture

Last patch did not have the cached changes only.

Dave Reid’s picture

OMG it appears to be working all correctly!

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url><loc>https://local.drupal.com/</loc><changefreq>daily</changefreq><priority>1.0</priority></url>
<url><loc>https://local.drupal.com/node/2</loc><lastmod>2019-12-03T23:39Z</lastmod><changefreq>daily</changefreq>
<xhtml:link rel="alternate" hreflang="es" href="https://local.drupal.com/es/node/2" />
<xhtml:link rel="alternate" hreflang="fr" href="https://local.drupal.com/fr/node/2" />
</url>
<url><loc>https://local.drupal.com/user/3</loc><lastmod>2019-11-04T15:14Z</lastmod><changefreq>monthly</changefreq></url>
</urlset>
Dave Reid’s picture

We were missing the xmlns:xhtml="http://www.w3.org/1999/xhtml attribute on the root XML, so let's just go ahead and add it globally.

Dave Reid’s picture

Fixing test that no longer assumes we can set a sitemap to language undefined, that seems a bit silly.

Dave Reid’s picture

I added support for ensuring that we also remove any invalid contexts in \Drupal\xmlsitemap\XmlSitemapStorage::doLoadMultiple(), fixed the empty context message on the sitemap edit form when there are contexts available, and also added alternate links for the homepage link.

Dave Reid’s picture

Grr, new last one was just the same.

Dave Reid’s picture

Reduced repeated code by adding an internal function for adding alternate links.

  • Dave Reid committed 7d359e9 on 8.x-1.x
    Issue #2941164 by Dave Reid, WidgetsBurritos: Added support for using...
Dave Reid’s picture

Status: Needs review » Fixed

Okay I feel really good about this. I'm going to go ahead and commit this to 8.x-1.x and I would *really* like some testing on the 8.x-1.x-dev branch from anyone who can!

Dave Reid’s picture

I have found that if a translated node, is also linked in a menu_link_content item that is not translated, this means that likely the menu_link_content item is read first, and none of the alternate links are added in this case. I'll file a follow-up issue for this.

Dave Reid’s picture

Status: Fixed » Needs review
FileSize
2.15 KB

This should help resolve it if we encounter a menu_link_content item for a node vs the node first in the xmlsitemap table in generation.

Dave Reid’s picture

Dave Reid’s picture

Fixing coding standards.

  • Dave Reid committed 64cbadb on 8.x-1.x
    Issue #2941164 by Dave Reid: Fixed multilingual alternate rel links...
Dave Reid’s picture

Status: Needs review » Fixed

Tested and committed #23 to 8.x-1.x.

Dave Reid’s picture

This has now been included in the 8.x-1.0-rc1 release, feedback and testing results would be welcome.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.