Problem/Motivation
In Drupal 9.3, it was possible to do the following within settings.php
:
$databases['default']['default'] = [
...
];
Database::setMultipleConnectionInfo($databases);
try {
Database::getConnection();
}
catch (Exception $e) {
// Do something
}
In Drupal 9.4, this now fails because the database driver is in core/modules/$driver, and that's not in the autoloader until after settings.php completes.
This can be worked around by adding $class_loader->addPsr4('Drupal\\mysql\\', 'core/modules/mysql/src/')
prior to calling Database::getConnection();
, but for sites with settings.php files that don't do that yet, this is a regression.
Acquia Cloud is one example where code like the above in settings.php (or rather, a .inc file included by settings.php) is done. I don't know if other Drupal hosting platforms employ similar constructs.
Steps to reproduce
Proposed resolution
Given that a workaround is possible, I don't know if we want to address this issue in core. If we do, then perhaps something like moving the current Settings::initialize()
code for setting up the autoloader into Database::getConnection()
might solve it? Maybe other ideas?