diff --git a/core/core.services.yml b/core/core.services.yml index 5abb7a0..2546ed3 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -315,7 +315,7 @@ services: - { name: backend_overridable } config.storage.schema: class: Drupal\Core\Config\ExtensionInstallStorage - arguments: ['@config.storage', 'config/schema'] + arguments: ['@config.storage', '%install_profile%', 'config/schema'] config.typed: class: Drupal\Core\Config\TypedConfigManager arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler'] diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 3c0cef1..179ca7f 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -722,8 +722,8 @@ function drupal_installation_attempted() { * currently active. This is the case for example during the first steps of * the installer or during unit tests. * - * @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. - * Use \Drupal::installProfile() or the install_profile container parameter + * @deprecated in Drupal 8.2.0, will be removed before Drupal 9.0.0. + * Use the install_profile container parameter or \Drupal::installProfile() * instead. */ function drupal_get_profile() { diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index dbd0c4d..d957713 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -149,7 +149,7 @@ public function installDefaultConfig($type, $name) { // Install any optional configuration entities whose dependencies can now // be met. This searches all the installed modules config/optional // directories. - $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE); + $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), \Drupal::installProfile(), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE); $this->installOptionalConfig($storage, [$type => $name]); } @@ -164,7 +164,7 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende $optional_profile_config = []; if (!$storage) { // Search the install profile's optional configuration too. - $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE); + $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), \Drupal::installProfile(), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE); // The extension install storage ensures that overrides are used. $profile_storage = NULL; } @@ -339,7 +339,7 @@ protected function createConfiguration($collection, array $config_to_create) { * {@inheritdoc} */ public function installCollectionDefaultConfig($collection) { - $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, $this->drupalInstallationAttempted()); + $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), \Drupal::installProfile(), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, $this->drupalInstallationAttempted()); // Only install configuration for enabled extensions. $enabled_extensions = $this->getEnabledExtensions(); $config_to_install = array_filter($storage->listAll(), function ($config_name) use ($enabled_extensions) { diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php index 8860a00..460dd34 100644 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -27,6 +27,13 @@ class ExtensionInstallStorage extends InstallStorage { protected $includeProfile = TRUE; /** + * Current install profile. + * + * @var string + */ + protected $profile; + + /** * Overrides \Drupal\Core\Config\InstallStorage::__construct(). * * @param \Drupal\Core\Config\StorageInterface $config_storage @@ -42,11 +49,12 @@ class ExtensionInstallStorage extends InstallStorage { * (optional) Whether to include the install profile in extensions to * search and to get overrides from. */ - public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE) { + public function __construct(StorageInterface $config_storage, $profile, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE) { $this->configStorage = $config_storage; $this->directory = $directory; $this->collection = $collection; $this->includeProfile = $include_profile; + $this->profile = $profile; } /** @@ -77,21 +85,20 @@ protected function getAllFolders() { $this->folders = array(); $this->folders += $this->getCoreNames(); - $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[$profile]); + unset($modules[$this->profile]); $profile_list = $listing->scan('profile'); - if ($profile && isset($profile_list[$profile])) { + if ($this->profile && isset($profile_list[$this->profile])) { // Prime the drupal_get_filename() static cache with the profile info // file location so we can use drupal_get_path() on the active profile // during the module scan. // @todo Remove as part of https://www.drupal.org/node/2186491 - drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname()); + drupal_get_filename('profile', $this->profile, $profile_list[$this->profile]->getPathname()); } $module_list_scan = $listing->scan('module'); $module_list = array(); @@ -116,12 +123,12 @@ protected function getAllFolders() { // The install profile can override module default configuration. We do // this by replacing the config file path from the module/theme with the // install profile version if there are any duplicates. - if (isset($profile)) { + if ($this->profile) { if (!isset($profile_list)) { $profile_list = $listing->scan('profile'); } - if (isset($profile_list[$profile])) { - $profile_folders = $this->getComponentNames(array($profile_list[$profile])); + if (isset($profile_list[$this->profile])) { + $profile_folders = $this->getComponentNames(array($profile_list[$this->profile])); $this->folders = $profile_folders + $this->folders; } } diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php index 46a0723..ac21dd2 100644 --- a/core/lib/Drupal/Core/DrupalKernelInterface.php +++ b/core/lib/Drupal/Core/DrupalKernelInterface.php @@ -143,8 +143,7 @@ public function loadLegacyIncludes(); /** * 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. + * If multiple profiles are distributions an exception will be thrown. * * @return string|FALSE * The machine name of any discovered distribution. FALSE if there are no diff --git a/core/lib/Drupal/Core/Installer/Exception/TooManyDistributionsException.php b/core/lib/Drupal/Core/Installer/Exception/TooManyDistributionsException.php index 5350726..d9028db 100644 --- a/core/lib/Drupal/Core/Installer/Exception/TooManyDistributionsException.php +++ b/core/lib/Drupal/Core/Installer/Exception/TooManyDistributionsException.php @@ -1,10 +1,5 @@ configStorage = $config_storage; $this->languageManager = $language_manager; - $this->requiredInstallStorage = new ExtensionInstallStorage($this->configStorage); - $this->optionalInstallStorage = new ExtensionInstallStorage($this->configStorage, ExtensionInstallStorage::CONFIG_OPTIONAL_DIRECTORY); + $this->requiredInstallStorage = new ExtensionInstallStorage($this->configStorage, \Drupal::installProfile()); + $this->optionalInstallStorage = new ExtensionInstallStorage($this->configStorage, \Drupal::installProfile(), ExtensionInstallStorage::CONFIG_OPTIONAL_DIRECTORY); } /** diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 8f97401..56dfe6f 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -311,6 +311,9 @@ public function containerBuild(ContainerBuilder $container) { // Set the default language on the minimal container. $this->container->setParameter('language.default_values', $this->defaultLanguageData()); + // Use the testing install profile. + $container->setParameter('install_profile', 'testing'); + $container->register('lock', 'Drupal\Core\Lock\NullLockBackend'); $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 15ecf1f..5876eb7 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -323,13 +323,13 @@ function testNoThemeByDefault() { } /** - * Tests that drupal_get_profile() returns NULL. + * Tests that \Drupal::installProfile() returns FALSE. * * As the currently active installation profile is used when installing * configuration, for example, this is essential to ensure test isolation. */ public function testDrupalGetProfile() { - $this->assertNull(drupal_get_profile()); + $this->assertFalse(\Drupal::installProfile()); } /** diff --git a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php index d0e6547..ab954e3 100644 --- a/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php +++ b/core/modules/system/src/Tests/Bootstrap/GetFilenameUnitTest.php @@ -13,15 +13,6 @@ class GetFilenameUnitTest extends KernelTestBase { /** - * {@inheritdoc} - */ - public function containerBuild(ContainerBuilder $container) { - parent::containerBuild($container); - // Use the testing install profile. - $container->setParameter('install_profile', 'testing'); - } - - /** * Tests that drupal_get_filename() works when the file is not in database. */ function testDrupalGetFilename() { diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php index 937043c..2c6bb01 100644 --- a/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php +++ b/core/modules/system/src/Tests/Installer/DistributionProfileExistingSettingsTest.php @@ -1,10 +1,5 @@ assertRaw(Html::escape($this->exceptionMessage)); + // The exceptions are expected. Do not interpret them as a test failure. + // Not using File API; a potential error must trigger a PHP warning. + unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log'); } /** diff --git a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileTest.php b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileTest.php index e3900fb..17d4660 100644 --- a/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerExistingSettingsMismatchProfileTest.php @@ -1,10 +1,5 @@