diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index ea6a9a8..6cc85d3 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -849,47 +849,11 @@ function drupal_installation_attempted() { * the installer or during unit tests. * * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. - * Use \Drupal\Core\Site\Settings::getInstallProfile() instead. + * Use \Drupal::installProfile() or the install.profile container parameter + * instead. */ function drupal_get_profile() { - global $install_state; - - if (drupal_installation_attempted()) { - // If the profile has been selected return it. - if (isset($install_state['parameters']['profile'])) { - $profile = $install_state['parameters']['profile']; - } - else { - $profile = NULL; - } - } - else { - $profile = Settings::getInstallProfile(); - } - - return $profile; -} - -/** - * Get the name of any discovered profile that is a distribution. - * - * If multiple profiles are distributions, then the first discovered profile - * will be selected. See https://www.drupal.org/node/2210443. - * - * @return string|null - * The machine name of any discovered distribution. - */ -function drupal_get_distribution() { - $container = Drupal::getContainer(); - $root = $container->get('app.root'); - $listing = new ExtensionDiscovery($root); - $listing->setProfileDirectories(array()); - foreach ($listing->scan('profile') as $profile) { - $info = \Drupal::service('info_parser')->parse($profile->getPathname()); - if (!empty($info['distribution'])) { - return $profile->getName(); - } - } + return \Drupal::installProfile(); } /** diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 7822bcd..e8ef040 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -1212,7 +1212,7 @@ function _install_select_profile(&$install_state) { } } // Check for a distribution. - if ($distribution = drupal_get_distribution()) { + if ($distribution = \Drupal::service('kernel')->getDistribution()) { return $distribution; } @@ -2299,7 +2299,7 @@ function install_display_requirements($install_state, $requirements) { * An array of information about the current installation state. */ function install_write_profile($install_state) { - $is_mismatch = Settings::getInstallProfile() !== $install_state['parameters']['profile']; + $is_mismatch = \Drupal::installProfile() !== $install_state['parameters']['profile']; if ($is_mismatch) { // Remember the profile which was used. $settings['settings']['install_profile'] = (object) array( diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 7621a48..08655a8 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -181,6 +181,16 @@ public static function root() { } /** + * Gets the active install profile. + * + * @return string|null + * The name of the any active install profile or distribution. + */ + public static function installProfile() { + return static::getContainer()->getParameter('install.profile'); + } + + /** * Indicates if there is a currently active request object. * * @return bool diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 56f97c4..fce8628 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -614,7 +614,7 @@ protected function drupalGetPath($type, $name) { protected function drupalGetProfile() { // Settings is safe to use because settings.php is written before any module // is installed. - return Settings::getInstallProfile(); + return \Drupal::installProfile(); } /** diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php index 56689d4..606b833 100644 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Core\Site\Settings; use Drupal\Core\Extension\ExtensionDiscovery; /** @@ -83,15 +82,14 @@ protected function getAllFolders() { $this->folders = array(); $this->folders += $this->getCoreNames(); - $install_profile = Settings::getInstallProfile(); - $profile = drupal_get_profile(); + $profile = \Drupal::installProfile(); $extensions = $this->configStorage->read('core.extension'); // @todo Remove this scan as part of https://www.drupal.org/node/2186491 $listing = new ExtensionDiscovery(\Drupal::root()); if (!empty($extensions['module'])) { $modules = $extensions['module']; // Remove the install profile as this is handled later. - unset($modules[$install_profile]); + unset($modules[$profile]); $profile_list = $listing->scan('profile'); if ($profile && isset($profile_list[$profile])) { // Prime the drupal_get_filename() static cache with the profile info diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index fd27416..3ff9d42 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -18,6 +18,7 @@ use Drupal\Core\DependencyInjection\ServiceProviderInterface; use Drupal\Core\DependencyInjection\YamlFileLoader; use Drupal\Core\Extension\ExtensionDiscovery; +use Drupal\Core\Extension\InfoParser; use Drupal\Core\File\MimeType\MimeTypeGuesser; use Drupal\Core\Http\TrustedHostsRequestFactory; use Drupal\Core\Language\Language; @@ -1079,6 +1080,7 @@ protected function compileContainer() { $container = $this->getContainerBuilder(); $container->set('kernel', $this); $container->setParameter('container.modules', $this->getModulesParameter()); + $container->setParameter('install.profile', $this->getInstallProfile()); // Get a list of namespaces and put it onto the container. $namespaces = $this->getModuleNamespacesPsr4($this->getModuleFileNames()); @@ -1448,4 +1450,33 @@ protected function addServiceFiles($service_yamls) { } return FALSE; } + + /** + * {@inheritdoc} + */ + public function getInstallProfile() { + $install_profile = Settings::get('install_profile'); + if (empty($install_profile)) { + $install_profile = $this->getDistribution(); + } + return $install_profile; + + } + + /** + * {@inheritdoc} + */ + public function getDistribution() { + $listing = new ExtensionDiscovery($this->root); + $listing->setProfileDirectories(array()); + $info_parser = new InfoParser(); + foreach ($listing->scan('profile') as $profile) { + $info = $info_parser->parse($profile->getPathname()); + if (!empty($info['distribution'])) { + return $profile->getName(); + } + } + return NULL; + } + } diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index 892952a..33ac646 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -134,4 +134,23 @@ public function preHandle(Request $request); */ public function loadLegacyIncludes(); + /** + * Gets the active install profile. + * + * @return string|null + * The name of the any active install profile or distribution. + */ + public function getInstallProfile(); + + /** + * Get the name of any discovered profile that is a distribution. + * + * If multiple profiles are distributions, then the first discovered profile + * will be selected. See https://www.drupal.org/node/2210443. + * + * @return string|null + * The machine name of any discovered distribution. + */ + public function getDistribution(); + } diff --git a/core/lib/Drupal/Core/InstallProfileFactory.php b/core/lib/Drupal/Core/InstallProfileFactory.php new file mode 100644 index 0000000..dc6b9af --- /dev/null +++ b/core/lib/Drupal/Core/InstallProfileFactory.php @@ -0,0 +1,42 @@ +drupalKernel = $drupal_kernel; + } + + /** + * Gets the install profile. + * + * @return string + */ + public function get() { + return $this->drupalKernel->getInstallProfile(); + } + +} + diff --git a/core/lib/Drupal/Core/Installer/InstallerKernel.php b/core/lib/Drupal/Core/Installer/InstallerKernel.php index cd3977c..7cf6f72 100644 --- a/core/lib/Drupal/Core/Installer/InstallerKernel.php +++ b/core/lib/Drupal/Core/Installer/InstallerKernel.php @@ -45,4 +45,28 @@ protected function addServiceFiles($service_yamls) { // In the beginning there is no settings.php and no service YAMLs. return parent::addServiceFiles($service_yamls ?: []); } + + /** + * {@inheritdoc} + */ + public function getInstallProfile() { + global $install_state; + + if ($install_state && empty($install_state['installation_finished'])) { + // If the profile has been selected return it. + if (isset($install_state['parameters']['profile'])) { + $profile = $install_state['parameters']['profile']; + } + else { + $profile = NULL; + } + } + else { + $profile = parent::getInstallProfile(); + } + + return $profile; + } + + } diff --git a/core/lib/Drupal/Core/Site/Settings.php b/core/lib/Drupal/Core/Site/Settings.php index 6f2d38a..21298b4 100644 --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@ -149,23 +149,6 @@ public static function getHashSalt() { } /** - * Gets the active install profile. - * - * @return string|null - * The name of the any active install profile or distribution. - */ - public static function getInstallProfile() { - $install_profile = self::$instance->get('install_profile'); - if (empty($install_profile)) { - $install_profile = drupal_get_distribution(); - // Stash install_profile as a Setting. - new Settings(self::$instance->getAll() + array('install_profile' => $install_profile)); - } - - return $install_profile; - } - - /** * Generates a prefix for APC user cache keys. * * A standardized prefix is useful to allow visual inspection of an APC user diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php index 54e6792..55d8d59 100644 --- a/core/modules/system/src/Tests/Installer/DistributionProfileTest.php +++ b/core/modules/system/src/Tests/Installer/DistributionProfileTest.php @@ -76,7 +76,7 @@ public function testInstalled() { $this->assertText($this->rootUser->getUsername()); // Confirm that Drupal recognizes this distribution as the current profile. - $this->assertEqual(Settings::getInstallProfile(), 'mydistro'); + $this->assertEqual(\Drupal::installProfile(), 'mydistro'); } } diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php index 92c1430..c664028 100644 --- a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsNoProfileTest.php @@ -73,7 +73,7 @@ protected function setUpSettings() { public function testInstaller() { $this->assertUrl('user/1'); $this->assertResponse(200); - $this->assertEqual('testing', Settings::getInstallProfile()); + $this->assertEqual('testing', \Drupal::installProfile()); } }