Best Way to Handle Variables Per Environment I have a custom module. It's FormBase to create a form. And on submit, I post values to an API. All this works. But I want to change the base URL variable (which is used in multiple methods) so that when you on any environment besides live you get a different URL.

I want to figure out the Drupal 8 way of doing this.

class EventSuggestionForm extends FormBase {
  // Needs to be different if not the live site...
  private $baseUrl = 'https://www.example.com';
  private $apiUrl = '/api/v1/';
...


Can I get some advice?
You can create a new setting in your settings.local.php or settings.php file like:

$settings['event_base_url'] = 'https://www.example.com';


or some people are adding switch block based on the server host, e.g.:

switch (@$_SERVER['HTTP_HOST']) {
  default:
  case 'dev.example.com':
     $settings['event_base_url'] = 'http://dev.example.com';
     break;
  case 'stage.example.com':
     $settings['event_base_url'] = 'https://test.example.com';
     break;
  case 'www.example.com':
  case 'preprod.example.com':
     $settings['event_base_url'] = 'https://live.example.com';
     break;
}


Then reference it in the code like:

use Drupal\Core\Site\Settings;
$baseUrl = Settings::get('event_base_url', '');


So your code would look like:

use Drupal\Core\Site\Settings;
class EventSuggestionForm extends FormBase {
  private $baseUrl;
  private $apiUrl = '/api/v1/';

  function __construct() {
    // Read value from the settings file.
    $this-&gt;$baseUrl = Settings::get('event_base_url', '');
  }
...


Then change this setting per environment in the settings file, similar as you've different database credentials per different environment. This is the same concept as it's used for the existing $settings['file_public_base_url'] parameter.