Commit 60cdc004 authored by Pawel G's avatar Pawel G

Issue #2736583 by guilopes, sebastianwestberg: Exclude entries without translation

parent 5e47e41f
...@@ -12,5 +12,6 @@ settings: ...@@ -12,5 +12,6 @@ settings:
max_links: 2000 max_links: 2000
cron_generate: true cron_generate: true
remove_duplicates: true remove_duplicates: true
skip_untranslated: false
batch_process_limit: 1500 batch_process_limit: 1500
...@@ -13,6 +13,9 @@ simple_sitemap.settings: ...@@ -13,6 +13,9 @@ simple_sitemap.settings:
remove_duplicates: remove_duplicates:
label: 'Remove duplicates' label: 'Remove duplicates'
type: boolean type: boolean
skip_untranslated:
label: 'Skip untranslated'
type: boolean
batch_process_limit: batch_process_limit:
label: 'Batch process limit' label: 'Batch process limit'
type: integer type: integer
......
...@@ -189,8 +189,19 @@ class Batch { ...@@ -189,8 +189,19 @@ class Batch {
$urls = []; $urls = [];
foreach ($languages as $language) { foreach ($languages as $language) {
$url_object->setOption('language', $language); $langcode = $language->getId();
$urls[$language->getId()] = $url_object->toString();
// Exclude untranslated paths.
if ($batch_info['skip_untranslated']) {
if ($language->isDefault() || $entity->hasTranslation($langcode)) {
$url_object->setOption('language', $language);
$urls[$langcode] = $url_object->toString();
}
}
else {
$url_object->setOption('language', $language);
$urls[$langcode] = $url_object->toString();
}
} }
$context['results']['generate'][] = [ $context['results']['generate'][] = [
...@@ -246,10 +257,27 @@ class Batch { ...@@ -246,10 +257,27 @@ class Batch {
if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context)) if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context))
continue; continue;
// Load entity object if this is an entity route.
$route_parameters = $url_object->getRouteParameters();
$entity = !empty(key($route_parameters))
? \Drupal::entityTypeManager()->getStorage(key($route_parameters))->load($route_parameters[key($route_parameters)])
: NULL;
$urls = []; $urls = [];
foreach ($languages as $language) { foreach ($languages as $language) {
$url_object->setOption('language', $language); $langcode = $language->getId();
$urls[$language->getId()] = $url_object->toString();
// Exclude untranslated paths.
if (!is_null($entity) && $batch_info['skip_untranslated']) {
if ($language->isDefault() || $entity->hasTranslation($langcode)) {
$url_object->setOption('language', $language);
$urls[$langcode] = $url_object->toString();
}
}
else {
$url_object->setOption('language', $language);
$urls[$langcode] = $url_object->toString();
}
} }
$context['results']['generate'][] = [ $context['results']['generate'][] = [
......
...@@ -10,7 +10,13 @@ use Drupal\Core\Form\FormStateInterface; ...@@ -10,7 +10,13 @@ use Drupal\Core\Form\FormStateInterface;
*/ */
class SimplesitemapSettingsForm extends ConfigFormBase { class SimplesitemapSettingsForm extends ConfigFormBase {
private $form_settings = ['max_links', 'cron_generate', 'remove_duplicates', 'batch_process_limit']; private $form_settings = [
'max_links',
'cron_generate',
'remove_duplicates',
'skip_untranslated',
'batch_process_limit'
];
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -69,7 +75,14 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -69,7 +75,14 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Exclude duplicate links'), '#title' => $this->t('Exclude duplicate links'),
'#description' => $this->t('Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'), '#description' => $this->t('Uncheck this to significantly speed up the sitemap generation process on a huge site (more than 20 000 indexed entities).'),
'#default_value' => $generator->getSetting('remove_duplicates'), '#default_value' => $generator->getSetting('remove_duplicates', TRUE),
];
$form['simple_sitemap_settings']['advanced']['skip_untranslated'] = [
'#type' => 'checkbox',
'#title' => $this->t('Skip non-existent translations'),
'#description' => $this->t('If unchecked, the sitemap will include links to all content translation variants, even when the content has not been translated yet. If checked, only links to the translated content are included.'),
'#default_value' => $generator->getSetting('skip_untranslated', FALSE),
]; ];
$form['simple_sitemap_settings']['advanced']['max_links'] = [ $form['simple_sitemap_settings']['advanced']['max_links'] = [
......
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