Commit eb9dc11c authored by catch's avatar catch

Issue #2958925 by alexpott, voleger, Vlad Bo, Wim Leers: Properly deprecate drupal_get_profile()

parent 6db9da0f
......@@ -778,7 +778,7 @@ 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.3.0, will be removed before Drupal 9.0.0.
* @deprecated in drupal:8.3.0 and is removed from drupal:9.0.0.
* Use the install_profile container parameter or \Drupal::installProfile()
* instead. If you are accessing the value before it is written to
* configuration during the installer use the $install_state global. If you
......@@ -791,6 +791,8 @@ function drupal_installation_attempted() {
function drupal_get_profile() {
global $install_state;
@trigger_error('drupal_get_profile() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use the install_profile container parameter or \Drupal::installProfile() 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. See https://www.drupal.org/node/2538996', E_USER_DEPRECATED);
if (drupal_installation_attempted()) {
// If the profile has been selected return it.
if (isset($install_state['parameters']['profile'])) {
......
......@@ -1655,7 +1655,7 @@ function install_profile_themes(&$install_state) {
* An array of information about the current installation state.
*/
function install_install_profile(&$install_state) {
\Drupal::service('module_installer')->install([drupal_get_profile()], FALSE);
\Drupal::service('module_installer')->install([$install_state['parameters']['profile']], FALSE);
// Install all available optional config. During installation the module order
// is determined by dependencies. If there are no dependencies between modules
// then the order in which they are installed is dependent on random factors
......@@ -1853,7 +1853,7 @@ function install_finish_translations(&$install_state) {
* A message informing the user that the installation is complete.
*/
function install_finished(&$install_state) {
$profile = drupal_get_profile();
$profile = $install_state['parameters']['profile'];
// Installation profiles are always loaded last.
module_set_weight($profile, 1000);
......
......@@ -107,7 +107,7 @@ function drupal_install_profile_distribution_name() {
}
// At all other times, we load the profile via standard methods.
else {
$profile = drupal_get_profile();
$profile = \Drupal::installProfile();
$info = system_get_info('module', $profile);
}
return isset($info['distribution']['name']) ? $info['distribution']['name'] : 'Drupal';
......@@ -132,7 +132,7 @@ function drupal_install_profile_distribution_version() {
}
// At all other times, we load the profile via standard methods.
else {
$profile = drupal_get_profile();
$profile = \Drupal::installProfile();
$info = system_get_info('module', $profile);
return $info['version'];
}
......
......@@ -155,9 +155,8 @@ function drupal_required_modules() {
$required = [];
// Unless called by the installer, an installation profile is required and
// must always be loaded. drupal_get_profile() also returns the installation
// profile in the installer, but only after it has been selected.
if ($profile = drupal_get_profile()) {
// must always be loaded.
if ($profile = \Drupal::installProfile()) {
$required[] = $profile;
}
......
......@@ -155,7 +155,7 @@ protected function getAllFolders() {
// yet because the system module may not yet be enabled during install.
// @todo Remove as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root());
if ($profile = drupal_get_profile()) {
if ($profile = \Drupal::installProfile()) {
$profile_list = $listing->scan('profile');
if (isset($profile_list[$profile])) {
// Prime the drupal_get_filename() static cache with the profile info
......
......@@ -242,7 +242,8 @@ public function getFormOptions(array $database) {
'#weight' => 10,
];
$profile = drupal_get_profile();
global $install_state;
$profile = $install_state['parameters']['profile'];
$db_prefix = ($profile == 'standard') ? 'drupal_' : $profile . '_';
$form['advanced_options']['prefix'] = [
'#type' => 'textfield',
......
......@@ -228,7 +228,7 @@ public function scan($type, $include_tests = NULL) {
*/
public function setProfileDirectoriesFromSettings() {
$this->profileDirectories = [];
$profile = drupal_get_profile();
$profile = \Drupal::installProfile();
// For SimpleTest to be able to test modules packaged together with a
// distribution we need to include the profile of the parent site (in
// which test runs are triggered).
......
......@@ -1108,7 +1108,7 @@ private function prepareEnvironment() {
// Use the original files directory to avoid nesting it within an existing
// simpletest directory if a test is executed within a test.
$this->originalFileDirectory = Settings::get('file_public_path', $site_path . '/files');
$this->originalProfile = drupal_get_profile();
$this->originalProfile = $this->originalContainer->getParameter('install_profile');
$this->originalUser = isset($user) ? clone $user : NULL;
// Prevent that session data is leaked into the UI test runner by closing
......
......@@ -44,7 +44,7 @@ function system_requirements($phase) {
// Display the currently active installation profile, if the site
// is not running the default installation profile.
$profile = drupal_get_profile();
$profile = \Drupal::installProfile();
if ($profile != 'standard') {
$info = system_get_info('module', $profile);
$requirements['install_profile'] = [
......@@ -820,7 +820,7 @@ function system_requirements($phase) {
// Display an error if a newly introduced dependency in a module is not resolved.
if ($phase == 'update') {
$profile = drupal_get_profile();
$profile = \Drupal::installProfile();
$files = \Drupal::service('extension.list.module')->getList();
foreach ($files as $module => $file) {
// Ignore disabled modules and installation profiles.
......
......@@ -27,6 +27,13 @@ public function testInstaller() {
// Ensure that the timezone is correct for sites under test after installing
// interactively.
$this->assertEqual($this->config('system.date')->get('timezone.default'), 'Australia/Sydney');
// Ensure the profile has a weight of 1000.
$module_extension_list = \Drupal::service('extension.list.module');
$extensions = $module_extension_list->getList();
$this->assertArrayHasKey('testing', $extensions);
$this->assertEquals(1000, $extensions['testing']->weight);
}
/**
......
......@@ -56,7 +56,7 @@ public function testInstalled() {
// Confirm that we are logged-in after installation.
$this->assertText($this->rootUser->getAccountName());
// Confirm that the minimal profile was installed.
$this->assertEqual(drupal_get_profile(), 'minimal');
$this->assertEqual(\Drupal::installProfile(), 'minimal');
}
}
<?php
namespace Drupal\Tests\Core\Bootstrap;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
/**
* Tests drupal_get_profile().
*
* @group Bootstrap
* @group legacy
* @see drupal_get_profile()
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class DrupalGetProfileLegacyTest extends UnitTestCase {
/**
* Config storage profile.
*
* @var string
*/
protected $bootstrapConfigStorageProfile;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
include $this->root . '/core/includes/bootstrap.inc';
}
/**
* Tests drupal_get_profile() deprecation.
*
* @expectedDeprecation drupal_get_profile() is deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use the install_profile container parameter or \Drupal::installProfile() 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. See https://www.drupal.org/node/2538996
* @dataProvider providerDrupalGetProfileInstallState
*/
public function testDrupalGetProfileLegacyInstallState($expected, array $install_state_array = NULL, $container_parameter = FALSE) {
// Set up global for install state.
global $install_state;
$install_state = $install_state_array;
// Set up the container.
$container = new ContainerBuilder();
$container->setParameter('install_profile', $container_parameter);
\Drupal::setContainer($container);
// Do test.
$this->assertEquals($expected, drupal_get_profile());
}
/**
* Data provider for testDrupalGetProfileInstallState().
*
* @return array
* Test data.
*
* @see testDrupalGetProfileInstallState
*/
public function providerDrupalGetProfileInstallState() {
$tests = [];
$tests['install_state_with_profile'] = [
'test_profile', [
'parameters' => [
'profile' => 'test_profile',
],
],
];
$tests['install_state_with_no_profile_overriding_container_profile'] = [
NULL,
[
'parameters' => [],
],
'test_profile',
];
$tests['no_install_state_with_container_profile'] = [
'container_profile',
NULL,
'container_profile',
];
return $tests;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment