Commit d4a92f8c authored by gbyte.co's avatar gbyte.co

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

parent 60cdc004
......@@ -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;
......
......@@ -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
];
......
......@@ -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;
}
/**
......
......@@ -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.
......
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