From abfc8cc0c55a53519eddcbc69da79bda53025c78 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 30 Jan 2024 21:32:26 -0800 Subject: [PATCH 1/4] Updated sitemap logic to avoid errors. --- .../EventSubscriber/CollectionSubscriber.php | 1 + modules/quant_sitemap/src/SitemapManager.php | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php b/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php index 53404690..e36a13a1 100644 --- a/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php +++ b/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php @@ -50,6 +50,7 @@ public function collectRoutes(CollectRoutesEvent $event) { } foreach ($this->manager->getSitemaps() as $route) { $event->queueItem(['route' => $route]); + \Drupal::logger('quant_sitemap')->notice("[route_item] @route", ['@route' => $route]); } } diff --git a/modules/quant_sitemap/src/SitemapManager.php b/modules/quant_sitemap/src/SitemapManager.php index 6d29287b..ab62a296 100644 --- a/modules/quant_sitemap/src/SitemapManager.php +++ b/modules/quant_sitemap/src/SitemapManager.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\Url; /** * Sitemap manager for Quant Sitemap. @@ -164,13 +165,27 @@ protected function getSitemapManager() { * A list of sitemap items. */ protected function getSimpleSitemaps() : array { - $items = ['/sitemap.xml', '/sitemap_generator/default/sitemap.xsl']; - foreach ($this->getSitemapManager()->getAllBundleSettings() as $variant => $def) { - if ($variant == "default") { - continue; + + // Gather XML and XSL files. + $items = []; + foreach ($this->getSitemapManager()->getSitemaps() as $id => $sitemap) { + + // Only add enabled sitemaps with content. + if ($sitemap->isEnabled() && $sitemap->contentStatus()) { + + // Note, creating an options array with 'absolute' => FALSE does not + // generate a relative URL, so we have to extract it. + $items[] = parse_url($sitemap->toUrl()->toString())['path']; + + // Figure out the XSL file for this sitemap. + $pluginId = $sitemap->getType()->getSitemapGenerator()->getPluginId(); + $items[] = '/sitemap_generator/' . $pluginId . '/sitemap.xsl'; } - $items[] = "/$variant/sitemap.xml"; } + + // Remove duplicate XSL files. + $items = array_unique($items); + return $items; } From f54eb2ff74554c0925e0df5486f10ce09cf69484 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 30 Jan 2024 21:34:45 -0800 Subject: [PATCH 2/4] Removed extra logging. --- .../quant_sitemap/src/EventSubscriber/CollectionSubscriber.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php b/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php index e36a13a1..53404690 100644 --- a/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php +++ b/modules/quant_sitemap/src/EventSubscriber/CollectionSubscriber.php @@ -50,7 +50,6 @@ public function collectRoutes(CollectRoutesEvent $event) { } foreach ($this->manager->getSitemaps() as $route) { $event->queueItem(['route' => $route]); - \Drupal::logger('quant_sitemap')->notice("[route_item] @route", ['@route' => $route]); } } From 28405e9fc1dee96c84d7d19c99c0909ba9181a25 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 30 Jan 2024 22:02:18 -0800 Subject: [PATCH 3/4] Removed unused use statement. --- modules/quant_sitemap/src/SitemapManager.php | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/quant_sitemap/src/SitemapManager.php b/modules/quant_sitemap/src/SitemapManager.php index ab62a296..b0277679 100644 --- a/modules/quant_sitemap/src/SitemapManager.php +++ b/modules/quant_sitemap/src/SitemapManager.php @@ -6,7 +6,6 @@ use Drupal\Core\Entity\EntityTypeManager; use Drupal\Core\Extension\ModuleExtensionList; use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\Core\Url; /** * Sitemap manager for Quant Sitemap. From b29660db1ac9a02e4c8362e20900cc3ceca63cf1 Mon Sep 17 00:00:00 2001 From: Kristen Pol Date: Tue, 30 Jan 2024 22:20:43 -0800 Subject: [PATCH 4/4] Added sitemap to drush code. --- src/Commands/QuantDrushCommands.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Commands/QuantDrushCommands.php b/src/Commands/QuantDrushCommands.php index fbc4714d..a487a864 100644 --- a/src/Commands/QuantDrushCommands.php +++ b/src/Commands/QuantDrushCommands.php @@ -180,6 +180,7 @@ public function prepare($options = ['reset' => 'true']) { 'file_paths', 'file_paths_textarea', 'robots', + 'export_sitemap', 'lunr', ];