As a developer of an application that requires multiple environments, each with a different base url, I would like the ability to specify my Default Base URL in settings.php.
Currently this module uses the State API for this setting which allows me to set a unique Default Base URL in each environment without risk of override via a config import. However, I must set this state manually for each environment via the module's settings page or via CLI. Allowing an override of this setting in settings.php using the $settings variable will allow me to define an environment's unique Default Base URL along with all of its other unique settings.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Arrow created an issue. See original summary.

Arrow’s picture

The attached patch allows you to set your default base URL by setting xmlsitemap_base_url in your settings.php like so:

$settings['xmlsitemap_base_url'] = 'http://www.example.com';

This will override any value previously set during installation of the module or set via the module settings page. It also disables the Default Base URL field on the settings page.

Arrow’s picture

Status: Active » Needs review
Arrow’s picture

MerryHamster’s picture

I use "version": "1.0.0-alpha2" and patch #4 doesn't work for me.
So I created the patch from #4 for one.

MerryHamster’s picture

Status: Needs review » Needs work

The last submitted patch, 5: 2999856-alpha2-5.patch, failed testing. View results

MerryHamster’s picture

Status: Needs work » Needs review
MerryHamster’s picture

FileSize
3.99 KB

Added a little fix for the patch from #5 for 'alpha2' version.

-      '#default_value' => $this->state->get('xmlsitemap_base_url'),
+      '#default_value' => $base_url_override ? $base_url_override : $this->state->get('xmlsitemap_base_url'),
Rob Holmes’s picture

Status: Needs review » Needs work

The last submitted patch, 10: 2999856-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Rob Holmes’s picture

Reinstate missing use Drupal\Core\Site\Settings;

KarenS’s picture

Status: Needs work » Needs review

We've run into this as well. We need to be able to deploy a number of new sites automatically from configuration and we don't want to have to manually configure this each time.

KarenS’s picture

Status: Needs review » Reviewed & tested by the community

Seems to work fine and tests pass.

Liam Morland’s picture

Instead of: $base_url_override ? TRUE : FALSE;
You can do: (bool) $base_url_override

pifagor’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.17 KB
alex_optim’s picture

Status: Needs review » Reviewed & tested by the community
pifagor’s picture

  • pifagor committed 46aaab3 on 8.x-1.x
    Issue #2999856 by Arrow, MerryHamster, Rob Holmes, pifagor, KarenS, Liam...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

leymannx’s picture

Nice work! Finally I found this one when I was halfway through changing the base URL to $GLOBALS['base_url'] everywhere. I wonder if this still wouldn't be a nice addition that if the Settings was omitted to fallback to $GLOBALS['base_url']. By that the value could also simply be passed from the --uri option using Drush.

drush -y xmlsitemap:rebuild --uri=example.com