From 76ed876118997178e68af3f0e0831a439f37a976 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Wed, 16 Oct 2013 11:58:49 +0100
Subject: [PATCH] Issue #2014017 by jlbellido, alvar0hurtad0, undertext, benjy,
 penyaskito, LinL: Replace drupal_container() with Drupal::service() in the
 system module.

---
 .../system/Tests/Path/UrlAlterFunctionalTest.php |  5 ++---
 .../system/Tests/Theme/TwigSettingsTest.php      | 16 ++++++++--------
 .../system/Tests/Update/UpdateScriptTest.php     |  2 +-
 core/modules/system/system.module                |  2 +-
 4 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php
index 0a0fd1893a33..35a4ef74a3c3 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php
@@ -111,8 +111,7 @@ protected function assertUrlOutboundAlter($original, $final) {
    * Assert that a inbound path is altered to an expected value.
    *
    * @param $original
-   *   A string with the aliased or un-normal path that is run through
-   *   drupal_container()->get('path.alias_manager')->getSystemPath().
+   *   The original path before it has been altered by inbound URL processing.
    * @param $final
    *   A string with the expected result after url().
    * @return
@@ -120,7 +119,7 @@ protected function assertUrlOutboundAlter($original, $final) {
    */
   protected function assertUrlInboundAlter($original, $final) {
     // Test inbound altering.
-    $result = drupal_container()->get('path.alias_manager')->getSystemPath($original);
+    $result = $this->container->get('path.alias_manager')->getSystemPath($original);
     $this->assertIdentical($result, $final, format_string('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result)));
   }
 }
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php
index e7bc98c141a3..958128c7c3cc 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigSettingsTest.php
@@ -39,13 +39,13 @@ function testTwigAutoReloadOverride() {
     $this->rebuildContainer();
 
     // Check isAutoReload() via the Twig service container.
-    $this->assertTrue(drupal_container()->get('twig')->isAutoReload(), 'Automatic reloading of Twig templates enabled.');
+    $this->assertTrue($this->container->get('twig')->isAutoReload(), 'Automatic reloading of Twig templates enabled.');
 
     // Disable auto reload and check the service container again.
     $this->settingsSet('twig_auto_reload', FALSE);
     $this->rebuildContainer();
 
-    $this->assertFalse(drupal_container()->get('twig')->isAutoReload(), 'Automatic reloading of Twig templates disabled.');
+    $this->assertFalse($this->container->get('twig')->isAutoReload(), 'Automatic reloading of Twig templates disabled.');
   }
 
   /**
@@ -57,19 +57,19 @@ function testTwigDebugOverride() {
     $this->rebuildContainer();
 
     // Check isDebug() via the Twig service container.
-    $this->assertTrue(drupal_container()->get('twig')->isDebug(), 'Twig debug enabled.');
-    $this->assertTrue(drupal_container()->get('twig')->isAutoReload(), 'Twig automatic reloading is enabled when debug is enabled.');
+    $this->assertTrue($this->container->get('twig')->isDebug(), 'Twig debug enabled.');
+    $this->assertTrue($this->container->get('twig')->isAutoReload(), 'Twig automatic reloading is enabled when debug is enabled.');
 
     // Override auto reload when debug is enabled.
     $this->settingsSet('twig_auto_reload', FALSE);
     $this->rebuildContainer();
-    $this->assertFalse(drupal_container()->get('twig')->isAutoReload(), 'Twig automatic reloading can be disabled when debug is enabled.');
+    $this->assertFalse($this->container->get('twig')->isAutoReload(), 'Twig automatic reloading can be disabled when debug is enabled.');
 
     // Disable debug and check the service container again.
     $this->settingsSet('twig_debug', FALSE);
     $this->rebuildContainer();
 
-    $this->assertFalse(drupal_container()->get('twig')->isDebug(), 'Twig debug disabled.');
+    $this->assertFalse($this->container->get('twig')->isDebug(), 'Twig debug disabled.');
   }
 
   /**
@@ -94,7 +94,7 @@ function testTwigCacheOverride() {
     // Get the template filename and the cache filename for
     // theme_test.template_test.html.twig.
     $template_filename = $templates['theme_test_template_test']['path'] . '/' . $templates['theme_test_template_test']['template'] . $extension;
-    $cache_filename = drupal_container()->get('twig')->getCacheFilename($template_filename);
+    $cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
 
     // Navigate to the page and make sure the template gets cached.
     $this->drupalGet('theme-test/template-test');
@@ -105,7 +105,7 @@ function testTwigCacheOverride() {
     $this->rebuildContainer();
 
     // This should return false after rebuilding the service container.
-    $new_cache_filename = drupal_container()->get('twig')->getCacheFilename($template_filename);
+    $new_cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
     $this->assertFalse($new_cache_filename, 'Twig environment does not return cache filename after caching is disabled.');
   }
 
diff --git a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
index 6102a70e4f1a..d581147cc67e 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Update/UpdateScriptTest.php
@@ -63,7 +63,7 @@ function testUpdateAccess() {
     // Access the update page as user 1.
     $user1 = user_load(1);
     $user1->pass_raw = user_password();
-    $user1->pass = drupal_container()->get('password')->hash(trim($user1->pass_raw));
+    $user1->pass = $this->container->get('password')->hash(trim($user1->pass_raw));
     db_query("UPDATE {users} SET pass = :pass WHERE uid = :uid", array(':pass' => $user1->getPassword(), ':uid' => $user1->id()));
     $this->drupalLogin($user1);
     $this->drupalGet($this->update_url, array('external' => TRUE));
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 84e3a4f5628b..9309d7502a24 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -2221,7 +2221,7 @@ function system_page_build(&$page) {
  */
 function system_custom_theme() {
   if (drupal_container()->isScopeActive('request')) {
-    $request = drupal_container()->get('request');
+    $request = \Drupal::request();
     $path = $request->attributes->get('_system_path');
     if (user_access('view the administration theme') && path_is_admin($path)) {
       return \Drupal::config('system.theme')->get('admin');
-- 
GitLab