...
 
...@@ -135,7 +135,9 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat ...@@ -135,7 +135,9 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) { if ($values['simple_sitemap_regenerate_now']) {
$generator->rebuildQueue()->generateSitemap(); $generator->setVariants(TRUE)
->rebuildQueue()
->generateSitemap();
} }
} }
} }
......
...@@ -163,7 +163,9 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase { ...@@ -163,7 +163,9 @@ class SimplesitemapCustomLinksForm extends SimplesitemapFormBase {
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$this->generator->rebuildQueue()->generateSitemap(); $this->generator->setVariants(TRUE)
->rebuildQueue()
->generateSitemap();
} }
} }
......
...@@ -196,7 +196,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase { ...@@ -196,7 +196,9 @@ class SimplesitemapEntitiesForm extends SimplesitemapFormBase {
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$this->generator->generateSitemap(); $this->generator->setVariants(TRUE)
->rebuildQueue()
->generateSitemap();
} }
} }
......
...@@ -129,9 +129,17 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -129,9 +129,17 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
} }
$sitemap_manager = $this->generator->getSitemapManager(); $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(); $sitemap_statuses = $this->fetchSitemapInstanceStatuses();
foreach ($sitemap_manager->getSitemapTypes() as $type_name => $type_definition) { foreach ($sitemap_manager->getSitemapTypes() as $type_name => $type_definition) {
if (!empty($variants = $sitemap_manager->getSitemapVariants($type_name, FALSE))) { 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] = [ $form['simple_sitemap_settings']['status']['types'][$type_name] = [
'#type' => 'details', '#type' => 'details',
'#title' => '<em>' . $type_definition['label'] . '</em> ' . $this->t('sitemaps'), '#title' => '<em>' . $type_definition['label'] . '</em> ' . $this->t('sitemaps'),
...@@ -150,16 +158,19 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -150,16 +158,19 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
$row['status'] = $this->t('pending'); $row['status'] = $this->t('pending');
} }
else { else {
$url = $GLOBALS['base_url'] . '/' . $variant_name . '/sitemap.xml';
switch ($sitemap_statuses[$variant_name]) { switch ($sitemap_statuses[$variant_name]) {
case 0: case 0:
$row['status'] = $this->t('generating'); $row['status'] = $this->t('generating');
break; break;
case 1: 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; break;
case 2: 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; break;
} }
} }
...@@ -376,7 +387,9 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase { ...@@ -376,7 +387,9 @@ class SimplesitemapSettingsForm extends SimplesitemapFormBase {
// Regenerate sitemaps according to user setting. // Regenerate sitemaps according to user setting.
if ($form_state->getValue('simple_sitemap_regenerate_now')) { if ($form_state->getValue('simple_sitemap_regenerate_now')) {
$this->generator->rebuildQueue()->generateSitemap(); $this->generator->setVariants(TRUE)
->rebuildQueue()
->generateSitemap();
} }
} }
......
...@@ -172,9 +172,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -172,9 +172,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
// Add sitemap chunk locations to document. // Add sitemap chunk locations to document.
foreach ($chunk_info as $chunk_data) { foreach ($chunk_info as $chunk_data) {
$this->writer->startElement('sitemap'); $this->writer->startElement('sitemap');
$this->writer->writeElement('loc', $this->getSitemapUrl($chunk_data->delta));
// 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('lastmod', date('c', $chunk_data->sitemap_created)); $this->writer->writeElement('lastmod', date('c', $chunk_data->sitemap_created));
$this->writer->endElement(); $this->writer->endElement();
} }
...@@ -328,14 +326,21 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S ...@@ -328,14 +326,21 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
} }
/** /**
* @param $delta * @param null $delta
* @param $variant
* @return \Drupal\Core\GeneratedUrl|string * @return \Drupal\Core\GeneratedUrl|string
*/ */
protected function getSitemapUrl($delta, $variant) { public function getSitemapUrl($delta = NULL) {
$parameters = NULL !== $delta ? ['page' => $delta] : [];
$url = $this->isDefaultVariant() $url = $this->isDefaultVariant()
? Url::fromRoute('simple_sitemap.sitemap_default', ['page' => $delta], $this->getSitemapUrlSettings()) ? Url::fromRoute(
: Url::fromRoute('simple_sitemap.sitemap_variant', ['variant' => $variant, 'page' => $delta], $this->getSitemapUrlSettings()); 'simple_sitemap.sitemap_default',
$parameters,
$this->getSitemapUrlSettings())
: Url::fromRoute(
'simple_sitemap.sitemap_variant',
$parameters + ['variant' => $this->sitemapVariant],
$this->getSitemapUrlSettings()
);
return $url->toString(); return $url->toString();
} }
......