Skip to content

Commit

Permalink
Updated sitemap logic to avoid errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Jan 31, 2024
1 parent e508a30 commit abfc8cc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}

Expand Down
25 changes: 20 additions & 5 deletions modules/quant_sitemap/src/SitemapManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit abfc8cc

Please sign in to comment.