From d4a92f8c82fe693bb91d8e12e8fa6dbd9e328d5c Mon Sep 17 00:00:00 2001 From: Pawel G Date: Sun, 21 Aug 2016 19:25:58 +0200 Subject: [PATCH] make getSetting() return a provided default value if setting does not exist --- src/Batch.php | 6 +++--- src/Form/SimplesitemapSettingsForm.php | 6 +++--- src/Simplesitemap.php | 9 ++++++--- src/SitemapGenerator.php | 5 +++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Batch.php b/src/Batch.php index 3566add..76696b8 100644 --- a/src/Batch.php +++ b/src/Batch.php @@ -172,15 +172,15 @@ class Batch { $url_object = $entity->toUrl(); } - // Do not index if this is an external path. + // Do not include external paths. if (!$url_object->isRouted()) continue; - // Do not include path if anonymous users do not have access to it. + // Do not include paths inaccessible to anonymous users. if (!$url_object->access($anon_user)) continue; - // Do not include path if it already exists. + // Do not include paths that have been already indexed. $path = $url_object->getInternalPath(); if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context)) continue; diff --git a/src/Form/SimplesitemapSettingsForm.php b/src/Form/SimplesitemapSettingsForm.php index 1643f9e..9e78b3b 100644 --- a/src/Form/SimplesitemapSettingsForm.php +++ b/src/Form/SimplesitemapSettingsForm.php @@ -63,7 +63,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { '#type' => 'checkbox', '#title' => $this->t('Regenerate the sitemap on every cron run'), '#description' => $this->t('Uncheck this if you intend to only regenerate the sitemap manually or via drush.'), - '#default_value' => $generator->getSetting('cron_generate'), + '#default_value' => $generator->getSetting('cron_generate', TRUE), ]; $form['simple_sitemap_settings']['advanced'] = [ @@ -91,7 +91,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { '#type' => 'textfield', '#maxlength' => 5, '#size' => 5, - '#default_value' => $generator->getSetting('max_links'), + '#default_value' => $generator->getSetting('max_links', 2000), ]; $form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [ @@ -100,7 +100,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { '#type' => 'textfield', '#maxlength' => 5, '#size' => 5, - '#default_value' => $generator->getSetting('batch_process_limit'), + '#default_value' => $generator->getSetting('batch_process_limit', 1500), '#required' => TRUE, //TODO: test ]; diff --git a/src/Simplesitemap.php b/src/Simplesitemap.php index d20e490..4c56ec0 100644 --- a/src/Simplesitemap.php +++ b/src/Simplesitemap.php @@ -391,12 +391,15 @@ class Simplesitemap { * @param string $name * Name of the setting, like 'max_links'. * + * @param mixed $default + * Value to be returned if the setting does not exist in the conifuration. + * * @return mixed - * The current setting from db or FALSE if setting does not exist. + * The current setting from db or a default value. */ - public function getSetting($name) { + public function getSetting($name, $default = FALSE) { $settings = $this->getConfig('settings'); - return isset($settings[$name]) ? $settings[$name] : FALSE; + return isset($settings[$name]) ? $settings[$name] : $default; } /** diff --git a/src/SitemapGenerator.php b/src/SitemapGenerator.php index 7abe0a3..10bedf0 100644 --- a/src/SitemapGenerator.php +++ b/src/SitemapGenerator.php @@ -41,8 +41,9 @@ class SitemapGenerator { 'from' => $this->generateFrom, 'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit')) ? $this->generator->getSetting('batch_process_limit') : NULL, - 'max_links' => $this->generator->getSetting('max_links'), - 'remove_duplicates' => $this->generator->getSetting('remove_duplicates'), + 'max_links' => $this->generator->getSetting('max_links', 2000), + 'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE), + 'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE), 'entity_types' => $this->generator->getConfig('entity_types'), ]); // Add custom link generating operation. -- GitLab