diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 19b6280..6b08dd9 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -8,10 +8,12 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Config\BootstrapConfigStorageFactory; use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Render\Markup; use Drupal\Component\Render\MarkupInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\Site\Settings; use Drupal\Core\Utility\Error; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -715,7 +717,7 @@ function drupal_installation_attempted() { * When this function is called during Drupal's initial installation process, * the name of the profile that's about to be installed is stored in the global * installation state. At all other times, the "install_profile" setting will be - * available in settings.php, or declared as a Distribution. + * available in container as a parameter. * * @return string|null $profile * The name of the installation profile or NULL if no installation profile is @@ -724,10 +726,38 @@ function drupal_installation_attempted() { * * @deprecated in Drupal 8.3.0, will be removed before Drupal 9.0.0. * Use the install_profile container parameter or \Drupal::installProfile() - * instead. + * instead. If you are accessing the value before it is written to + * configuration during the installer use the $install_state global. If you + * need to access the value before container is available you can use + * BootstrapConfigStorageFactory to load the value directly from + * configuration. */ function drupal_get_profile() { - return \Drupal::installProfile(); + 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; + } + } + elseif (\Drupal::hasContainer()) { + $profile = \Drupal::installProfile(); + } + // Try to load the value directly from configuration. + if (empty($profile)) { + $profile = BootstrapConfigStorageFactory::getDatabaseStorage()->read('core.extension')['profile']; + } + // A BC layer just in in case this only exists in Settings. Introduced in + // Drupal 8.3.x and will be removed before Drupal 9.0.0. + if (empty($profile)) { + $profile = Settings::get('install_profile'); + } + + return $profile; } /** diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 4a156a2..81c9190 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -5,11 +5,9 @@ * Contains \Drupal. */ -use Drupal\Core\Config\BootstrapConfigStorageFactory; use Drupal\Core\DependencyInjection\ContainerNotInitializedException; use Symfony\Component\DependencyInjection\ContainerInterface; use Drupal\Core\Url; -use Drupal\Core\Site\Settings; /** * Static Service Container wrapper. @@ -187,22 +185,10 @@ public static function root() { * Gets the active install profile. * * @return string|null - * The name of the any active install profile or distribution. + * The name of the active install profile. */ public static function installProfile() { - if (static::hasContainer()) { - $profile = static::getContainer()->getParameter('install_profile'); - } - else { - $config_storage = BootstrapConfigStorageFactory::getDatabaseStorage(); - $profile = $config_storage->read('core.extension')['profile']; - } - // A BC layer just in in case this only exists in Settings. Introduced in - // Drupal 8.3.x and will be removed before Drupal 9.0.0. - if (empty($profile)) { - $profile = Settings::get('install_profile'); - } - return empty($profile) ? NULL : $profile; + return static::getContainer()->getParameter('install_profile'); } /** diff --git a/core/modules/block/src/Tests/BlockUiTest.php b/core/modules/block/src/Tests/BlockUiTest.php index 35c3b5f..f2bcaae 100644 --- a/core/modules/block/src/Tests/BlockUiTest.php +++ b/core/modules/block/src/Tests/BlockUiTest.php @@ -230,7 +230,7 @@ public function testContextAwareBlocks() { $this->assertTrue(!empty($definition), 'The context-aware test block exists.'); $edit = [ 'region' => 'content', - 'settings[context_mapping][user]' => '@block_test.multiple_static_context:user2', + 'settings[context_mapping][user]' => '@block_test.multiple_static_context:userB', ]; $this->drupalPostForm($block_url, $edit, 'Save block'); diff --git a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php index 58a262d..9ca8132 100644 --- a/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php +++ b/core/modules/block/tests/modules/block_test/src/ContextProvider/MultipleStaticContext.php @@ -47,9 +47,9 @@ public function __construct(AccountInterface $account, EntityManagerInterface $e public function getRuntimeContexts(array $unqualified_context_ids) { $current_user = $this->userStorage->load($this->account->id()); - $context1 = new Context(new ContextDefinition('entity:user', 'User 1'), $current_user); + $context1 = new Context(new ContextDefinition('entity:user', 'User A'), $current_user); - $context2 = new Context(new ContextDefinition('entity:user', 'User 2'), $current_user); + $context2 = new Context(new ContextDefinition('entity:user', 'User B'), $current_user); $cacheability = new CacheableMetadata(); $cacheability->setCacheContexts(['user']); @@ -58,8 +58,8 @@ public function getRuntimeContexts(array $unqualified_context_ids) { $context2->addCacheableDependency($cacheability); return [ - 'user1' => $context1, - 'user2' => $context2, + 'userA' => $context1, + 'userB' => $context2, ]; }