Commit 46aaab3c authored by pifagor's avatar pifagor

Issue #2999856 by Arrow, MerryHamster, Rob Holmes, pifagor, KarenS, Liam...

Issue #2999856 by Arrow, MerryHamster, Rob Holmes, pifagor, KarenS, Liam Morland, alex_optim: Allow Override of Base URL in settings.php
parent 0429cb8a
......@@ -5,6 +5,7 @@ namespace Drupal\xmlsitemap\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Render\Element;
use Drupal\Core\Site\Settings;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -177,13 +178,15 @@ class XmlSitemapSettingsForm extends ConfigFormBase {
'#field_prefix' => file_build_uri(''),
'#required' => TRUE,
];
$base_url_override = Settings::get('xmlsitemap_base_url', FALSE);
$form['advanced']['xmlsitemap_base_url'] = [
'#type' => 'textfield',
'#title' => t('Default base URL'),
'#default_value' => $this->state->get('xmlsitemap_base_url'),
'#default_value' => $base_url_override ? $base_url_override : $this->state->get('xmlsitemap_base_url'),
'#size' => 30,
'#description' => t('This is the default base URL used for sitemaps and sitemap links.'),
'#required' => TRUE,
'#disabled' => !empty($base_url_override),
];
$form['advanced']['lastmod_format'] = [
'#type' => 'select',
......
......@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Psr\Log\LoggerInterface;
......@@ -233,7 +234,7 @@ class XmlSitemapGenerator implements XmlSitemapGeneratorInterface {
$url_options = $sitemap->uri['options'];
$url_options += [
'absolute' => TRUE,
'base_url' => rtrim($this->state->get('xmlsitemap_base_url'), '/'),
'base_url' => rtrim(Settings::get('xmlsitemap_base_url', $this->state->get('xmlsitemap_base_url')), '/'),
'language' => $this->languageManager->getDefaultLanguage(),
// @todo Figure out a way to bring back the alias preloading optimization.
// 'alias' => $this->config->get('prefetch_aliases'),
......
......@@ -25,6 +25,7 @@ use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Link;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\Core\Site\Settings;
use Drupal\xmlsitemap\Entity\XmlSitemap;
use Drupal\xmlsitemap\XmlSitemapInterface;
use Symfony\Component\HttpFoundation\Response;
......@@ -457,7 +458,7 @@ function xmlsitemap_sitemap_uri(XmlSitemapInterface $sitemap) {
\Drupal::moduleHandler()->alter('xmlsitemap_context_url_options', $uri['options'], $context);
$uri['options'] += [
'absolute' => TRUE,
'base_url' => \Drupal::state()->get('xmlsitemap_base_url'),
'base_url' => Settings::get('xmlsitemap_base_url', \Drupal::state()->get('xmlsitemap_base_url')),
];
return $uri;
}
......
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