function drupal_install_system

Same name in other branches
  1. 7.x includes/install.inc \drupal_install_system()
  2. 8.9.x core/includes/install.inc \drupal_install_system()
  3. 10 core/includes/install.inc \drupal_install_system()
  4. 11.x core/includes/install.inc \drupal_install_system()

Installs the system module.

Separated from the installation of other modules so core system functions can be made available while other modules are installed.

Parameters

array $install_state: An array of information about the current installation state. This is used to set the default language.

1 call to drupal_install_system()
install_base_system in core/includes/install.core.inc
Installation task; install the base functionality Drupal needs to bootstrap.

File

core/includes/install.inc, line 586

Code

function drupal_install_system($install_state) {
    // Remove the service provider of the early installer.
    unset($GLOBALS['conf']['container_service_providers']['InstallerServiceProvider']);
    // Add the normal installer service provider.
    $GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\\Core\\Installer\\NormalInstallerServiceProvider';
    // Get the existing request.
    $request = \Drupal::request();
    // Reboot into a full production environment to continue the installation.
    
    /** @var \Drupal\Core\Installer\InstallerKernel $kernel */
    $kernel = \Drupal::service('kernel');
    $kernel->shutdown();
    // Have installer rebuild from the disk, rather then building from scratch.
    $kernel->rebuildContainer(FALSE);
    // Reboot the kernel with new container.
    $kernel->boot();
    $kernel->preHandle($request);
    // Ensure our request includes the session if appropriate.
    if (PHP_SAPI !== 'cli') {
        $request->setSession($kernel->getContainer()
            ->get('session'));
    }
    // Before having installed the system module and being able to do a module
    // rebuild, prime the \Drupal\Core\Extension\ModuleExtensionList static cache
    // with the module's location.
    // @todo Try to install system as any other module, see
    //   https://www.drupal.org/node/2719315.
    \Drupal::service('extension.list.module')->setPathname('system', 'core/modules/system/system.info.yml');
    // Install base system configuration.
    \Drupal::service('config.installer')->installDefaultConfig('core', 'core');
    // Store the installation profile in configuration to populate the
    // 'install_profile' container parameter.
    \Drupal::configFactory()->getEditable('core.extension')
        ->set('profile', $install_state['parameters']['profile'])
        ->save();
    $connection = Database::getConnection();
    $provider = $connection->getProvider();
    // When the database driver is provided by a module, then install that module.
    // This module must be installed before any other module, as it must be able
    // to override any call to hook_schema() or any "backend_overridable" service.
    // In edge cases, a driver module may extend from another driver module (for
    // instance, a module to provide backward compatibility with a database
    // version no longer supported by core). In order for the extended classes to
    // be autoloadable, the extending module should list the extended module in
    // its dependencies, and here the dependencies will be installed as well.
    if ($provider !== 'core') {
        $autoload = $connection->getConnectionOptions()['autoload'] ?? '';
        if (str_contains($autoload, 'src/Driver/Database/')) {
            $kernel->getContainer()
                ->get('module_installer')
                ->install([
                $provider,
            ], TRUE);
        }
    }
    // Install System module.
    $kernel->getContainer()
        ->get('module_installer')
        ->install([
        'system',
    ], FALSE);
    // Ensure default language is saved.
    if (isset($install_state['parameters']['langcode'])) {
        \Drupal::configFactory()->getEditable('system.site')
            ->set('langcode', (string) $install_state['parameters']['langcode'])
            ->set('default_langcode', (string) $install_state['parameters']['langcode'])
            ->save(TRUE);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.