At the moment I'm implementing a module for managing multi-site sites

It would be desirable to implement switching a choice of a site in backend and accordingly change settings database connection on the fly

example

Sites /

Default /
Settings.php

Site1 /
Settings.php

Site2 /
Settings.php
The work is done on the default site. After selecting in the admin panel - "work at site1", its settings are loaded in default on the fly without changing the settings.php. In particular, only the connection settings of the database change

Tried the following methods

Changing the active connection according to the default-extra scheme

\ Drupal \ Core \ Database \ Database :: setActiveConnection ('extra');

Did not work out
I tried at the initialization level to place a call at the initialization level

Did not work out
Is it possible to do this? There is an idea on putting a variable in a session and in settings.php checking it. But how to access it from settings.php?

Comments

sprite’s picture

Study and consider the domain module for Drupal 8:

https://www.drupal.org/project/domain

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...