Commit 3f1e1c16 authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: base_url and developer_mode variables stored...

Issue #2249723 by andrei.dincu: base_url and developer_mode variables stored with \Drupal::state() instead of \Drupal::config()
parent 29a7229e
......@@ -7,8 +7,6 @@ prefetch_aliases: 1
chunk_size: 'auto'
batch_limit: 100
path: 'xmlsitemap'
base_url: ''
developer_mode: 0
frontpage_priority: 1.0
frontpage_changefreq: 86400
lastmod_format: 'Y-m-d\TH:i\Z'
......
......@@ -31,12 +31,6 @@ xmlsitemap.settings:
path:
type: string
label: 'Path of the XML generated files'
base_url:
type: string
label: 'URL for XML sitemap file'
developer_mode:
type: integer
label: 'Check if is developer mode'
frontpage_priority:
type: float
label: 'Priority of the frontpage'
......
......@@ -24,7 +24,7 @@ class XmlSitemapController extends ControllerBase {
$file = xmlsitemap_sitemap_get_file($sitemap, $chunk);
// Provide debugging information if enabled.
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
if (\Drupal::state()->get('developer_mode')) {
$output = array();
$context = xmlsitemap_get_current_context();
$output[] = "Current context: " . print_r($context, TRUE);
......
......@@ -47,8 +47,8 @@ class XmlSitemapRebuildForm extends ConfigFormBase {
'#description' => t('If no link types are selected, the sitemap files will just be regenerated.'),
'#multiple' => TRUE,
'#options' => $rebuild_types,
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('rebuild_needed') || !\Drupal::config('xmlsitemap.settings')->get('developer_mode') ? $rebuild_types : array(),
'#access' => \Drupal::config('xmlsitemap.settings')->get('developer_mode'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('rebuild_needed') || !\Drupal::state()->get('developer_mode') ? $rebuild_types : array(),
'#access' => \Drupal::state()->get('developer_mode'),
);
return parent::buildForm($form, $form_state);
}
......
......@@ -53,7 +53,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
'#type' => 'details',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => !\Drupal::config('xmlsitemap.settings')->get('developer_mode'),
'#collapsed' => !\Drupal::state()->get('developer_mode'),
'#weight' => 10,
);
$form['advanced']['gz'] = array(
......@@ -95,7 +95,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
$form['advanced']['base_url'] = array(
'#type' => 'textfield',
'#title' => t('Default base URL'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('base_url'),
'#default_value' => \Drupal::state()->get('base_url'),
'#size' => 30,
'#description' => t('This is the default base URL used for sitemaps and sitemap links.'),
'#required' => TRUE,
......@@ -116,7 +116,7 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
$form['advanced']['developer_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Enable developer mode to expose additional settings.'),
'#default_value' => \Drupal::config('xmlsitemap.settings')->get('developer_mode'),
'#default_value' => \Drupal::state()->get('developer_mode'),
);
$form['xmlsitemap_settings'] = array(
......@@ -179,10 +179,15 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
// Save any changes to the frontpage link.
$values = $form_state['values'];
xmlsitemap_link_save(array('type' => 'frontpage', 'id' => 0, 'loc' => ''));
\Drupal::state()->set('developer_mode',$values['developer_mode']);
\Drupal::state()->set('base_url',$values['base_url']);
unset($values['developer_mode']);
unset($values['base_url']);
foreach ($values as $key => $value) {
\Drupal::config('xmlsitemap.settings')->set($key,$value);
}
\Drupal::config('xmlsitemap.settings')->save();
parent::submitForm($form, $form_state);
}
......
......@@ -53,7 +53,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
// Attempt to increase the memory limit.
_xmlsitemap_set_memory_limit();
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
if (\Drupal::state()->get('developer_mode')) {
watchdog('xmlsitemap', 'Starting XML sitemap generation. Memory usage: @memory-peak.', array(
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
), WATCHDOG_DEBUG
......@@ -137,7 +137,7 @@ class XmlSitemapGeneratorService implements XmlSitemapGeneratorInterface {
$url_options = $sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => \Drupal::config('xmlsitemap.settings')->get('base_url'),
'base_url' => \Drupal::state()->get('base_url'),
'language' => language_default(),
'alias' => \Drupal::config('xmlsitemap.settings')->get('prefetch_aliases'),
);
......
......@@ -58,7 +58,7 @@ function _xmlsitemap_regenerate_before() {
// Attempt to increase the memory limit.
_xmlsitemap_set_memory_limit();
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
if (\Drupal::state()->get('developer_mode')) {
watchdog('xmlsitemap', 'Starting XML sitemap generation. Memory usage: @memory-peak.', array(
'@memory-peak' => format_size(memory_get_peak_usage(TRUE)),
), WATCHDOG_DEBUG
......@@ -149,7 +149,7 @@ function xmlsitemap_generate_chunk(XmlSitemapInterface $sitemap, XMLSitemapWrite
$url_options = $sitemap->uri['options'];
$url_options += array(
'absolute' => TRUE,
'base_url' => \Drupal::config('xmlsitemap.settings')->get('base_url'),
'base_url' => \Drupal::state()->get('base_url'),
'language' => language_default(),
'alias' => \Drupal::config('xmlsitemap.settings')->get('prefetch_aliases'),
);
......
......@@ -104,7 +104,7 @@ function xmlsitemap_requirements($phase) {
$requirements['xmlsitemap_file_size']['description'] = $t('You have exceeded the maximum sitemap file size of @size. If possible, decrease the number of links per sitemap page.', array('@size' => format_size(XMLSITEMAP_MAX_SITEMAP_FILESIZE)));
$requirements['xmlsitemap_file_size']['severity'] = REQUIREMENT_ERROR;
}
elseif (!\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
elseif (!\Drupal::state()->get('developer_mode')) {
unset($requirements['xmlsitemap_file_size']);
}
......@@ -347,6 +347,8 @@ function xmlsitemap_install() {
'context' => serialize($context),
))
->execute();
\Drupal::state()->set('base_url', url(NULL, array('absolute' => TRUE)));
\Drupal::state()->set('developer_mode',0);
// @todo Does the sitemap show up on first install or is it a 404 page?
}
......
......@@ -519,7 +519,7 @@ function xmlsitemap_sitemap_uri(XmlSitemapInterface $sitemap) {
drupal_alter('xmlsitemap_context_url_options', $uri['options'], $sitemap->getContext());
$uri['options'] += array(
'absolute' => TRUE,
'base_url' => \Drupal::config('xmlsitemap.settings')->get('base_url')
'base_url' => \Drupal::state()->get('base_url')
);
return $uri;
}
......
......@@ -45,7 +45,7 @@ function xmlsitemap_output_chunk() {
$file = xmlsitemap_sitemap_get_file($sitemap, $chunk);
// Provide debugging information if enabled.
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode', 0) && isset($_GET['debug'])) {
if (\Drupal::state()->get('developer_mode', 0) && isset($_GET['debug'])) {
$output = array();
$context = xmlsitemap_get_current_context();
$output[] = "Current context: " . print_r($context, TRUE);
......
......@@ -75,7 +75,7 @@ class XMLSitemapWriter extends XMLWriter {
*/
public function getRootAttributes() {
$attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
if (\Drupal::state()->get('developer_mode')) {
$attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
$attributes['xsi:schemaLocation'] = 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
}
......@@ -177,7 +177,7 @@ class XMLSitemapIndexWriter extends XMLSitemapWriter {
public function getRootAttributes() {
$attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
if (\Drupal::config('xmlsitemap.settings')->get('developer_mode')) {
if (\Drupal::state()->get('developer_mode')) {
$attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
$attributes['xsi:schemaLocation'] = 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd';
}
......
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