Commit 95dd7f74 authored by webchick's avatar webchick

Issue #2001206 by andypost, penyaskito, herom, Crell, ebeyrent, DmitryDrozdik:...

Issue #2001206 by andypost, penyaskito, herom, Crell, ebeyrent, DmitryDrozdik: Replace drupal_container() with Drupal::service().
parent bd3791cb
......@@ -2127,20 +2127,6 @@ function drupal_get_bootstrap_phase() {
return drupal_bootstrap();
}
/**
* Retrieves the Drupal Container to standardize object construction.
*
* @deprecated This function has been replaced by the \Drupal class. Use that
* instead.
*
* @return Symfony\Component\DependencyInjection\ContainerInterface|bool
* The instance of the ContainerInterface used to set up and maintain
* object instances or FALSE if none exist yet.
*/
function drupal_container() {
return \Drupal::getContainer();
}
/**
* Returns the list of enabled modules.
*
......
......@@ -106,7 +106,7 @@ function ($value) use ($name) {
* The name of the module or theme to install default configuration for.
*/
function config_uninstall_default_config($type, $name) {
$storage = drupal_container()->get('config.storage');
$storage = \Drupal::service('config.storage');
$config_names = $storage->listAll($name . '.');
foreach ($config_names as $config_name) {
\Drupal::config($config_name)->delete();
......@@ -119,7 +119,7 @@ function config_uninstall_default_config($type, $name) {
* @see \Drupal\Core\Config\StorageInterface::listAll()
*/
function config_get_storage_names_with_prefix($prefix = '') {
return drupal_container()->get('config.storage')->listAll($prefix);
return \Drupal::service('config.storage')->listAll($prefix);
}
/**
......@@ -163,18 +163,19 @@ function config($name) {
* The configuration context object.
*/
function config_context_enter($context_name) {
if (drupal_container()->has($context_name)) {
$context = drupal_container()->get($context_name);
$container = \Drupal::getContainer();
if ($container->has($context_name)) {
$context = $container->get($context_name);
}
elseif (class_exists($context_name) && in_array('Drupal\Core\Config\Context\ContextInterface', class_implements($context_name))) {
$context = drupal_container()
$context = $container
->get('config.context.factory')
->get($context_name);
}
else {
throw new ConfigException(sprintf('Unknown config context service or class: %s', $context_name));
}
drupal_container()
$container
->get('config.factory')
->enterContext($context);
return $context;
......@@ -187,8 +188,7 @@ function config_context_enter($context_name) {
* @see \Drupal\Core\Config\ConfigFactory
*/
function config_context_leave() {
drupal_container()
->get('config.factory')
\Drupal::service('config.factory')
->leaveContext();
}
......@@ -218,7 +218,7 @@ function config_get_entity_type_by_name($name) {
* @return \Drupal\Core\Config\TypedConfigManager
*/
function config_typed() {
return drupal_container()->get('config.typed');
return \Drupal::service('config.typed');
}
/**
......
......@@ -2206,8 +2206,8 @@ function install_finished(&$install_state) {
drupal_cron_run();
// Save a snapshot of the initially installed configuration.
$active = drupal_container()->get('config.storage');
$snapshot = drupal_container()->get('config.storage.snapshot');
$active = \Drupal::service('config.storage');
$snapshot = \Drupal::service('config.storage.snapshot');
config_import_create_snapshot($active, $snapshot);
return $output;
......
......@@ -3092,7 +3092,7 @@ function _menu_router_build($callbacks, $save = FALSE) {
// if the list has changed.
if ($path_roots != \Drupal::state()->get('menu_path_roots')) {
\Drupal::state()->set('menu_path_roots', array_values($path_roots));
drupal_container()->get('path.alias_manager')->cacheClear();
\Drupal::service('path.alias_manager')->cacheClear();
}
_menu_router_save($menu, $masks);
}
......
......@@ -82,8 +82,8 @@ function current_path() {
// @todo Remove the check for whether the request service exists and the
// fallback code below, once the path alias logic has been figured out in
// http://drupal.org/node/1269742.
if (drupal_container()->isScopeActive('request')) {
$path = drupal_container()->get('request')->attributes->get('_system_path');
if (\Drupal::getContainer()->isScopeActive('request')) {
$path = \Drupal::request()->attributes->get('_system_path');
if ($path !== NULL) {
return $path;
}
......@@ -112,7 +112,7 @@ function path_load($conditions) {
elseif (!is_array($conditions)) {
return FALSE;
}
return drupal_container()->get('path.crud')->load($conditions);
return \Drupal::service('path.crud')->load($conditions);
}
/**
......
......@@ -106,8 +106,8 @@ public static function setContainer(ContainerInterface $container) {
/**
* Returns the currently active global container.
*
* @deprecated This method is only useful for the testing environment, and as
* a BC shiv for drupal_container(). It should not be used otherwise.
* @deprecated This method is only useful for the testing environment. It
* should not be used otherwise.
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
......
......@@ -33,7 +33,7 @@ function testDrupalGetFilename() {
// Assert that the test is meaningful by making sure the keyvalue service
// does not exist.
$this->assertFalse(drupal_container()->has('keyvalue'), 'The container has no keyvalue service.');
$this->assertFalse(\Drupal::getContainer()->has('keyvalue'), 'The container has no keyvalue service.');
// Retrieving the location of a module.
$this->assertIdentical(drupal_get_filename('module', 'xmlrpc'), 'core/modules/xmlrpc/xmlrpc.module', 'Retrieve module location.');
......
......@@ -47,7 +47,7 @@ public function setUp() {
// Use a non-db cache backend, so that we can use DiscoveryTestBase (which
// extends UnitTestBase).
// @todo switch to injecting the MemoryBackend http://drupal.org/node/1903346
drupal_container()->set("cache.$this->cacheBin", new MemoryBackend($this->cacheBin));
\Drupal::getContainer()->set("cache.$this->cacheBin", new MemoryBackend($this->cacheBin));
// Create discovery objects to test.
$this->emptyDiscovery = new StaticDiscovery();
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\system\Tests\ServiceProvider\ServiceProviderTest.
* Contains \Drupal\system\Tests\ServiceProvider\ServiceProviderTest.
*/
namespace Drupal\system\Tests\ServiceProvider;
......@@ -33,8 +33,9 @@ public static function getInfo() {
* Tests that services provided by module service providers get registered to the DIC.
*/
function testServiceProviderRegistration() {
$this->assertTrue(drupal_container()->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed');
$this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
$container = \Drupal::getContainer();
$this->assertTrue($container->getDefinition('file.usage')->getClass() == 'Drupal\\service_provider_test\\TestFileUsage', 'Class has been changed');
$this->assertTrue($container->has('service_provider_test_class'), 'The service_provider_test_class service has been registered to the DIC');
// The event subscriber method in the test class calls drupal_set_message with
// a message saying it has fired. This will fire on every page request so it
// should show up on the front page.
......@@ -48,11 +49,11 @@ function testServiceProviderRegistration() {
function testServiceProviderRegistrationDynamic() {
// Uninstall the module and ensure the service provider's service is not registered.
\Drupal::moduleHandler()->uninstall(array('service_provider_test'));
$this->assertFalse(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');
$this->assertFalse(\Drupal::getContainer()->has('service_provider_test_class'), 'The service_provider_test_class service does not exist in the DIC.');
// Install the module and ensure the service provider's service is registered.
\Drupal::moduleHandler()->install(array('service_provider_test'));
$this->assertTrue(drupal_container()->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
$this->assertTrue(\Drupal::getContainer()->has('service_provider_test_class'), 'The service_provider_test_class service exists in the DIC.');
}
}
......@@ -44,7 +44,7 @@
// Create six users
$query = db_insert('users')->fields(array('uid', 'name', 'pass', 'mail', 'status', 'created', 'access'));
$password_hasher = drupal_container()->get('password');
$password_hasher = \Drupal::service('password');
for ($i = 0; $i < 6; $i++) {
$name = "test user $i";
$pass = md5("test PassW0rd $i !(.)");
......@@ -252,7 +252,7 @@
'alias' => "content/poll/$i/results",
'source' => "node/$node->nid/results",
);
drupal_container()->get('path.crud')->save($path['source'], $path['alias']);
\Drupal::service('path.crud')->save($path['source'], $path['alias']);
// Add some votes
$node = node_load($node->nid);
......
......@@ -83,7 +83,7 @@
include_once $core . '/includes/password.inc';
include_once $core . '/includes/bootstrap.inc';
$password_hasher = drupal_container()->get('password');
$password_hasher = \Drupal::service('password');
foreach ($passwords as $password) {
print("\npassword: $password \t\thash: ". $password_hasher->hash($password) ."\n");
......
......@@ -51,7 +51,7 @@ function twig_render_template($template_file, $variables) {
$output = array(
'debug_prefix' => '',
'debug_info' => '',
'rendered_markup' => drupal_container()->get('twig')->loadTemplate($template_file)->render($variables),
'rendered_markup' => \Drupal::service('twig')->loadTemplate($template_file)->render($variables),
'debug_suffix' => '',
);
if (settings()->get('twig_debug', FALSE)) {
......
......@@ -193,8 +193,9 @@ function update_info_page() {
// Change query-strings on css/js files to enforce reload for all users.
_drupal_flush_css_js();
// Flush the cache of all data for the update status module.
drupal_container()->get('keyvalue.expirable')->get('update')->deleteAll();
drupal_container()->get('keyvalue.expirable')->get('update_available_release')->deleteAll();
$keyvalue = \Drupal::service('keyvalue.expirable');
$keyvalue->get('update')->deleteAll();
$keyvalue->get('update_available_release')->deleteAll();
update_task_list('info');
drupal_set_title('Drupal database update');
......@@ -254,7 +255,7 @@ function update_access_allowed() {
$module_filenames['user'] = 'core/modules/user/user.module';
$module_handler->setModuleList($module_filenames);
$module_handler->reload();
drupal_container()->get('kernel')->updateModules($module_filenames, $module_filenames);
\Drupal::service('kernel')->updateModules($module_filenames, $module_filenames);
return user_access('administer software updates');
}
catch (\Exception $e) {
......
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