Commit d4a92f8c authored by Pawel G's avatar Pawel G

make getSetting() return a provided default value if setting does not exist

parent 60cdc004
...@@ -172,15 +172,15 @@ class Batch { ...@@ -172,15 +172,15 @@ class Batch {
$url_object = $entity->toUrl(); $url_object = $entity->toUrl();
} }
// Do not index if this is an external path. // Do not include external paths.
if (!$url_object->isRouted()) if (!$url_object->isRouted())
continue; 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)) if (!$url_object->access($anon_user))
continue; continue;
// Do not include path if it already exists. // Do not include paths that have been already indexed.
$path = $url_object->getInternalPath(); $path = $url_object->getInternalPath();
if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context)) if ($batch_info['remove_duplicates'] && self::pathProcessed($path, $context))
continue; continue;
......
...@@ -63,7 +63,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -63,7 +63,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => $this->t('Regenerate the sitemap on every cron run'), '#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.'), '#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'] = [ $form['simple_sitemap_settings']['advanced'] = [
...@@ -91,7 +91,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -91,7 +91,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield', '#type' => 'textfield',
'#maxlength' => 5, '#maxlength' => 5,
'#size' => 5, '#size' => 5,
'#default_value' => $generator->getSetting('max_links'), '#default_value' => $generator->getSetting('max_links', 2000),
]; ];
$form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [ $form['simple_sitemap_settings']['advanced']['batch_process_limit'] = [
...@@ -100,7 +100,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase { ...@@ -100,7 +100,7 @@ class SimplesitemapSettingsForm extends ConfigFormBase {
'#type' => 'textfield', '#type' => 'textfield',
'#maxlength' => 5, '#maxlength' => 5,
'#size' => 5, '#size' => 5,
'#default_value' => $generator->getSetting('batch_process_limit'), '#default_value' => $generator->getSetting('batch_process_limit', 1500),
'#required' => TRUE, //TODO: test '#required' => TRUE, //TODO: test
]; ];
......
...@@ -391,12 +391,15 @@ class Simplesitemap { ...@@ -391,12 +391,15 @@ class Simplesitemap {
* @param string $name * @param string $name
* Name of the setting, like 'max_links'. * 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 * @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'); $settings = $this->getConfig('settings');
return isset($settings[$name]) ? $settings[$name] : FALSE; return isset($settings[$name]) ? $settings[$name] : $default;
} }
/** /**
......
...@@ -41,8 +41,9 @@ class SitemapGenerator { ...@@ -41,8 +41,9 @@ class SitemapGenerator {
'from' => $this->generateFrom, 'from' => $this->generateFrom,
'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit')) 'batch_process_limit' => !empty($this->generator->getSetting('batch_process_limit'))
? $this->generator->getSetting('batch_process_limit') : NULL, ? $this->generator->getSetting('batch_process_limit') : NULL,
'max_links' => $this->generator->getSetting('max_links'), 'max_links' => $this->generator->getSetting('max_links', 2000),
'remove_duplicates' => $this->generator->getSetting('remove_duplicates'), 'skip_untranslated' => $this->generator->getSetting('skip_untranslated', FALSE),
'remove_duplicates' => $this->generator->getSetting('remove_duplicates', TRUE),
'entity_types' => $this->generator->getConfig('entity_types'), 'entity_types' => $this->generator->getConfig('entity_types'),
]); ]);
// Add custom link generating operation. // Add custom link generating operation.
......
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