Commit 715f500a authored by gbyte.co's avatar gbyte.co Committed by gbyte.co

Issue #3057052: Use generated sitemap URLs on settings page

parent fa3a2f92
......@@ -129,9 +129,17 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
}
$sitemap_manager = $this->generator->getSitemapManager();
$sitemap_settings = [
'base_url' => $this->generator->getSetting('base_url', ''),
'default_variant' => $this->generator->getSetting('default_variant', NULL),
];
$sitemap_statuses = $this->fetchSitemapInstanceStatuses();
foreach ($sitemap_manager->getSitemapTypes() as $type_name => $type_definition) {
if (!empty($variants = $sitemap_manager->getSitemapVariants($type_name, FALSE))) {
$sitemap_generator = $sitemap_manager
->getSitemapGenerator($type_definition['sitemapGenerator'])
->setSettings($sitemap_settings);
$form['simple_sitemap_settings']['status']['types'][$type_name] = [
'#type' => 'details',
'#title' => '<em>' . $type_definition['label'] . '</em> ' . $this->t('sitemaps'),
......@@ -150,16 +158,19 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$row['status'] = $this->t('pending');
}
else {
$url = $GLOBALS['base_url'] . '/' . $variant_name . '/sitemap.xml';
switch ($sitemap_statuses[$variant_name]) {
case 0:
$row['status'] = $this->t('generating');
break;
case 1:
$row['status']['data']['#markup'] = $this->t('<a href="@url" target="_blank">published</a>', ['@url' => $url]);
$row['status']['data']['#markup'] = $this->t('<a href="@url" target="_blank">published</a>',
['@url' => $sitemap_generator->setSitemapVariant($variant_name)->getSitemapUrl()]
);
break;
case 2:
$row['status'] = $this->t('<a href="@url" target="_blank">published</a>, regenerating', ['@url' => $url]);
$row['status'] = $this->t('<a href="@url" target="_blank">published</a>, regenerating',
['@url' => $sitemap_generator->setSitemapVariant($variant_name)->getSitemapUrl()]
);
break;
}
}
......
......@@ -172,9 +172,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
// Add sitemap chunk locations to document.
foreach ($chunk_info as $chunk_data) {
$this->writer->startElement('sitemap');
// Build the URL from route to be able to show potentially aliased paths.
$this->writer->writeElement('loc', $this->getSitemapUrl($chunk_data->delta, $chunk_data->type));
$this->writer->writeElement('loc', $this->getSitemapUrl($chunk_data->delta));
$this->writer->writeElement('lastmod', date('c', $chunk_data->sitemap_created));
$this->writer->endElement();
}
......@@ -328,14 +326,21 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
}
/**
* @param $delta
* @param $variant
* @param null $delta
* @return \Drupal\Core\GeneratedUrl|string
*/
protected function getSitemapUrl($delta, $variant) {
public function getSitemapUrl($delta = NULL) {
$parameters = NULL !== $delta ? ['page' => $delta] : [];
$url = $this->isDefaultVariant()
? Url::fromRoute('simple_sitemap.sitemap_default', ['page' => $delta], $this->getSitemapUrlSettings())
: Url::fromRoute('simple_sitemap.sitemap_variant', ['variant' => $variant, 'page' => $delta], $this->getSitemapUrlSettings());
? Url::fromRoute(
'simple_sitemap.sitemap_default',
$parameters,
$this->getSitemapUrlSettings())
: Url::fromRoute(
'simple_sitemap.sitemap_variant',
$parameters + ['variant' => $this->sitemapVariant],
$this->getSitemapUrlSettings()
);
return $url->toString();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment