From 338e96695ee52d17a059951e516ee950aed6fccb Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sun, 11 Jan 2015 22:25:46 +0000
Subject: [PATCH] Issue #2328293 by keopx, JeroenT, ianthomas_uk, ashutoshsngh,
 rpayanm, hudo, a_thakur: Remove usage of language_list()

---
 .../Entity/Sql/SqlContentEntityStorage.php    | 18 +++++--
 core/lib/Drupal/Core/Session/UserSession.php  |  4 +-
 core/modules/comment/src/CommentStorage.php   | 10 ++--
 .../content_translation.module                |  5 +-
 .../src/ContentTranslationHandler.php         | 35 ++++++++++---
 .../language/src/Form/LanguageDeleteForm.php  | 18 +++++--
 .../src/Form/NegotiationBrowserForm.php       |  2 +-
 .../language/src/Form/NegotiationUrlForm.php  | 37 +++++++++++++-
 .../src/Plugin/Condition/Language.php         | 50 +++++++++++++++++--
 .../Tests/LanguageListModuleInstallTest.php   |  8 +--
 .../locale/src/Form/TranslateEditForm.php     |  2 +-
 .../locale/src/Form/TranslateFormBase.php     |  2 +-
 .../node/src/Plugin/views/field/Node.php      |  2 +-
 core/modules/user/src/Entity/User.php         |  4 +-
 .../user/src/Plugin/views/field/Language.php  |  2 +-
 core/modules/user/src/UserStorage.php         | 10 ++--
 .../Sql/SqlContentEntityStorageTest.php       | 22 ++++++--
 17 files changed, 185 insertions(+), 46 deletions(-)

diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
index af14f6edc69c..f9a272730462 100644
--- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
+++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
@@ -25,6 +25,7 @@
 use Drupal\Core\Field\FieldStorageDefinitionInterface;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\field\FieldStorageConfigInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -121,6 +122,13 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
    */
   protected $cacheBackend;
 
+  /**
+   * The language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface
+   */
+  protected $languageManager;
+
   /**
    * {@inheritdoc}
    */
@@ -129,7 +137,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
       $entity_type,
       $container->get('database'),
       $container->get('entity.manager'),
-      $container->get('cache.entity')
+      $container->get('cache.entity'),
+      $container->get('language_manager')
     );
   }
 
@@ -155,12 +164,15 @@ public function getFieldStorageDefinitions() {
    *   The entity manager.
    * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
    *   The cache backend to be used.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
    */
-  public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache) {
+  public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
     parent::__construct($entity_type);
     $this->database = $database;
     $this->entityManager = $entity_manager;
     $this->cacheBackend = $cache;
+    $this->languageManager = $language_manager;
     $this->initTableLayout();
   }
 
@@ -1251,7 +1263,7 @@ protected function loadFieldItems(array $entities) {
     }
 
     // Load field data.
-    $langcodes = array_keys(language_list(LanguageInterface::STATE_ALL));
+    $langcodes = array_keys($this->languageManager->getLanguages(LanguageInterface::STATE_ALL));
     foreach ($storage_definitions as $field_name => $storage_definition) {
       $table = $load_current ? $table_mapping->getDedicatedDataTableName($storage_definition) : $table_mapping->getDedicatedRevisionTableName($storage_definition);
 
diff --git a/core/lib/Drupal/Core/Session/UserSession.php b/core/lib/Drupal/Core/Session/UserSession.php
index 1a23a0463379..92629d50eb13 100644
--- a/core/lib/Drupal/Core/Session/UserSession.php
+++ b/core/lib/Drupal/Core/Session/UserSession.php
@@ -183,7 +183,7 @@ public function isAnonymous() {
    * {@inheritdoc}
    */
   function getPreferredLangcode($fallback_to_default = TRUE) {
-    $language_list = language_list();
+    $language_list = \Drupal::languageManager()->getLanguages();
     if (!empty($this->preferred_langcode) && isset($language_list[$this->preferred_langcode])) {
       return $language_list[$this->preferred_langcode]->getId();
     }
@@ -196,7 +196,7 @@ function getPreferredLangcode($fallback_to_default = TRUE) {
    * {@inheritdoc}
    */
   function getPreferredAdminLangcode($fallback_to_default = TRUE) {
-    $language_list = language_list();
+    $language_list = \Drupal::languageManager()->getLanguages();
     if (!empty($this->preferred_admin_langcode) && isset($language_list[$this->preferred_admin_langcode])) {
       return $language_list[$this->preferred_admin_langcode]->getId();
     }
diff --git a/core/modules/comment/src/CommentStorage.php b/core/modules/comment/src/CommentStorage.php
index 2cbaed722a3f..7e3e867b225f 100644
--- a/core/modules/comment/src/CommentStorage.php
+++ b/core/modules/comment/src/CommentStorage.php
@@ -15,6 +15,7 @@
 use Drupal\Core\Entity\FieldableEntityInterface;
 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -45,9 +46,11 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
    *   Cache backend instance to use.
    * @param \Drupal\Core\Session\AccountInterface $current_user
    *   The current user.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
    */
-  public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache) {
-    parent::__construct($entity_info, $database, $entity_manager, $cache);
+  public function __construct(EntityTypeInterface $entity_info, Connection $database, EntityManagerInterface $entity_manager, AccountInterface $current_user, CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
+    parent::__construct($entity_info, $database, $entity_manager, $cache, $language_manager);
     $this->currentUser = $current_user;
   }
 
@@ -60,7 +63,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
       $container->get('database'),
       $container->get('entity.manager'),
       $container->get('current_user'),
-      $container->get('cache.entity')
+      $container->get('cache.entity'),
+      $container->get('language_manager')
     );
   }
 
diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module
index 7ca20d45c69b..89a6cbbfb274 100644
--- a/core/modules/content_translation/content_translation.module
+++ b/core/modules/content_translation/content_translation.module
@@ -242,10 +242,7 @@ function content_translation_translate_access(EntityInterface $entity) {
  * @todo Move to \Drupal\content_translation\ContentTranslationManager.
  */
 function content_translation_controller($entity_type_id) {
-  $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
-  // @todo Throw an exception if the key is missing.
-  $class = $entity_type->getHandlerClass('translation');
-  return new $class($entity_type);
+  return \Drupal::entityManager()->getHandler($entity_type_id, 'translation');
 }
 
 /**
diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php
index 88f57aea5844..eb805477c01c 100644
--- a/core/modules/content_translation/src/ContentTranslationHandler.php
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -8,18 +8,21 @@
 namespace Drupal\content_translation;
 
 use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityHandlerInterface;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Drupal\Core\Render\Element;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Base class for content translation handlers.
  *
  * @ingroup entity_api
  */
-class ContentTranslationHandler implements ContentTranslationHandlerInterface {
+class ContentTranslationHandler implements ContentTranslationHandlerInterface, EntityHandlerInterface {
 
   /**
    * The type of the entity being translated.
@@ -35,15 +38,35 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface {
    */
   protected $entityType;
 
+  /**
+   * The language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface
+   */
+  protected $languageManager;
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
+    return new static(
+      $entity_type,
+      $container->get('language_manager')
+    );
+  }
+
   /**
    * Initializes an instance of the content translation controller.
    *
    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
    *   The info array of the given entity type.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
    */
-  public function __construct(EntityTypeInterface $entity_type) {
+  public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager) {
     $this->entityTypeId = $entity_type->id();
     $this->entityType = $entity_type;
+    $this->languageManager = $language_manager;
   }
 
   /**
@@ -104,7 +127,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
 
     // Adjust page title to specify the current language being edited, if we
     // have at least one translation.
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
     if (isset($languages[$form_langcode]) && ($has_translations || $new_translation)) {
       $title = $this->entityFormTitle($entity);
       // When editing the original values display just the entity label.
@@ -137,7 +160,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
           '#submit' => array(array($this, 'entityFormSourceChange')),
         ),
       );
-      foreach (language_list(LanguageInterface::STATE_CONFIGURABLE) as $language) {
+      foreach ($this->languageManager->getLanguages() as $language) {
         if (isset($translations[$language->getId()])) {
           $form['source_langcode']['source']['#options'][$language->getId()] = $language->getName();
         }
@@ -158,7 +181,7 @@ public function entityFormAlter(array &$form, FormStateInterface $form_state, En
       $language_select = &$language_widget['widget'][0]['value'];
       if ($language_select['#type'] == 'language_select') {
         $options = array();
-        foreach (\Drupal::languageManager()->getLanguages() as $language) {
+        foreach ($this->languageManager->getLanguages() as $language) {
           // Show the current language, and the languages for which no
           // translation already exists.
           if (empty($translations[$language->getId()]) || $language->getId() == $entity_langcode) {
@@ -461,7 +484,7 @@ public function entityFormSourceChange($form, FormStateInterface $form_state) {
       'source' => $source,
       'target' => $form_object->getFormLangcode($form_state),
     ));
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
     drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->getName())));
   }
 
diff --git a/core/modules/language/src/Form/LanguageDeleteForm.php b/core/modules/language/src/Form/LanguageDeleteForm.php
index 32fb889a5efd..9f9667384550 100644
--- a/core/modules/language/src/Form/LanguageDeleteForm.php
+++ b/core/modules/language/src/Form/LanguageDeleteForm.php
@@ -11,6 +11,7 @@
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Routing\UrlGeneratorInterface;
 use Drupal\Core\Url;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
@@ -28,14 +29,24 @@ class LanguageDeleteForm extends EntityConfirmFormBase {
    */
   protected $urlGenerator;
 
+  /**
+   * The language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface
+   */
+  protected $languageManager;
+
   /**
    * Constructs a new LanguageDeleteForm object.
    *
    * @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
    *   The url generator service.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
    */
-  public function __construct(UrlGeneratorInterface $url_generator) {
+  public function __construct(UrlGeneratorInterface $url_generator, LanguageManagerInterface $language_manager) {
     $this->urlGenerator = $url_generator;
+    $this->languageManager = $language_manager;
   }
 
   /**
@@ -43,7 +54,8 @@ public function __construct(UrlGeneratorInterface $url_generator) {
    */
   public static function create(ContainerInterface $container) {
     return new static(
-      $container->get('url_generator')
+      $container->get('url_generator'),
+      $container->get('language_manager')
     );
   }
 
@@ -96,7 +108,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     }
 
     // Throw a 404 when attempting to delete a non-existing language.
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
     if (!isset($languages[$langcode])) {
       throw new NotFoundHttpException();
     }
diff --git a/core/modules/language/src/Form/NegotiationBrowserForm.php b/core/modules/language/src/Form/NegotiationBrowserForm.php
index 8cbac111e8e7..d7722141f317 100644
--- a/core/modules/language/src/Form/NegotiationBrowserForm.php
+++ b/core/modules/language/src/Form/NegotiationBrowserForm.php
@@ -60,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     $form = array();
 
     // Initialize a language list to the ones available, including English.
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
 
     $existing_languages = array();
     foreach ($languages as $langcode => $language) {
diff --git a/core/modules/language/src/Form/NegotiationUrlForm.php b/core/modules/language/src/Form/NegotiationUrlForm.php
index dcb721aa1389..979cca9038f4 100644
--- a/core/modules/language/src/Form/NegotiationUrlForm.php
+++ b/core/modules/language/src/Form/NegotiationUrlForm.php
@@ -9,6 +9,9 @@
 
 use Drupal\Core\Form\ConfigFormBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
 
 /**
@@ -16,6 +19,36 @@
  */
 class NegotiationUrlForm extends ConfigFormBase {
 
+  /**
+   * The language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface
+   */
+  protected $languageManager;
+
+  /**
+   * Constructs a new LanguageDeleteForm object.
+   *
+   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+   *   The factory for configuration objects.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
+   */
+  public function __construct(ConfigFactoryInterface $config_factory, LanguageManagerInterface $language_manager) {
+    parent::__construct($config_factory);
+    $this->languageManager = $language_manager;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('config.factory'),
+      $container->get('language_manager')
+    );
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -69,7 +102,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       ),
     );
 
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
     $prefixes = language_negotiation_url_prefixes();
     $domains = language_negotiation_url_domains();
     foreach ($languages as $langcode => $language) {
@@ -98,7 +131,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    * Implements \Drupal\Core\Form\FormInterface::validateForm().
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
 
     // Count repeated values for uniqueness check.
     $count = array_count_values($form_state->getValue('prefix'));
diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php
index fa09f3b6adfb..77fdc0841241 100644
--- a/core/modules/language/src/Plugin/Condition/Language.php
+++ b/core/modules/language/src/Plugin/Condition/Language.php
@@ -10,6 +10,9 @@
 use Drupal\Core\Condition\ConditionPluginBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Provides a 'Language' condition.
@@ -23,15 +26,54 @@
  * )
  *
  */
-class Language extends ConditionPluginBase {
+class Language extends ConditionPluginBase implements ContainerFactoryPluginInterface {
+
+  /**
+   * The Language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface
+   */
+  protected $languageManager;
+
+  /**
+   * Creates a new Language instance.
+   *
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
+   * @param array $configuration
+   *   The plugin configuration, i.e. an array with configuration values keyed
+   *   by configuration option name. The special key 'context' may be used to
+   *   initialize the defined contexts by setting it to an array of context
+   *   values keyed by context names.
+   * @param string $plugin_id
+   *   The plugin_id for the plugin instance.
+   * @param mixed $plugin_definition
+   *   The plugin implementation definition.
+   */
+  public function __construct(LanguageManagerInterface $language_manager, array $configuration, $plugin_id, $plugin_definition) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+    $this->languageManager = $language_manager;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static(
+      $container->get('language_manager'),
+      $configuration,
+      $plugin_id,
+      $plugin_definition
+    );
+  }
 
   /**
    * {@inheritdoc}
    */
   public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
-    if (\Drupal::languageManager()->isMultilingual()) {
+    if ($this->languageManager->isMultilingual()) {
       // Fetch languages.
-      $languages = \Drupal::languageManager()->getLanguages(LanguageInterface::STATE_CONFIGURABLE);
+      $languages = $this->languageManager->getLanguages();
       $langcodes_options = array();
       foreach ($languages as $language) {
         $langcodes_options[$language->getId()] = $language->getName();
@@ -65,7 +107,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s
    * {@inheritdoc}
    */
   public function summary() {
-    $language_list = language_list(LanguageInterface::STATE_ALL);
+    $language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL);
     $selected = $this->configuration['langcodes'];
     // Reduce the language list to an array of language names.
     $language_names = array_reduce($language_list, function(&$result, $item) use ($selected) {
diff --git a/core/modules/language/src/Tests/LanguageListModuleInstallTest.php b/core/modules/language/src/Tests/LanguageListModuleInstallTest.php
index 891ddf892da1..eae3f1a90a35 100644
--- a/core/modules/language/src/Tests/LanguageListModuleInstallTest.php
+++ b/core/modules/language/src/Tests/LanguageListModuleInstallTest.php
@@ -10,8 +10,8 @@
 use Drupal\simpletest\WebTestBase;
 
 /**
- * Tests enabling Language if a module exists that calls language_list during
- * installation.
+ * Tests enabling Language if a module exists that calls
+ * LanguageManager::getLanguages() during installation.
  *
  * @group language
  */
@@ -28,8 +28,8 @@ class LanguageListModuleInstallTest extends WebTestBase {
    * Tests enabling Language.
    */
   function testModuleInstallLanguageList() {
-    // Since language_list uses static caches we need to do this by enabling
-    // the module using the UI.
+    // Since LanguageManager::getLanguages() uses static caches we need to do
+    // this by enabling the module using the UI.
     $admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
     $this->drupalLogin($admin_user);
     $edit = array();
diff --git a/core/modules/locale/src/Form/TranslateEditForm.php b/core/modules/locale/src/Form/TranslateEditForm.php
index 1e3239a7fbda..454a65b40698 100644
--- a/core/modules/locale/src/Form/TranslateEditForm.php
+++ b/core/modules/locale/src/Form/TranslateEditForm.php
@@ -32,7 +32,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     $langcode = $filter_values['langcode'];
 
     $this->languageManager->reset();
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
 
     $langname = isset($langcode) ? $languages[$langcode]->getName() : "- None -";
 
diff --git a/core/modules/locale/src/Form/TranslateFormBase.php b/core/modules/locale/src/Form/TranslateFormBase.php
index f2dbc824003e..b894f17e9e7b 100644
--- a/core/modules/locale/src/Form/TranslateFormBase.php
+++ b/core/modules/locale/src/Form/TranslateFormBase.php
@@ -161,7 +161,7 @@ protected function translateFilters() {
 
     // Get all languages, except English.
     $this->languageManager->reset();
-    $languages = language_list();
+    $languages = $this->languageManager->getLanguages();
     $language_options = array();
     foreach ($languages as $langcode => $language) {
       if ($langcode != 'en' || locale_translate_english()) {
diff --git a/core/modules/node/src/Plugin/views/field/Node.php b/core/modules/node/src/Plugin/views/field/Node.php
index 0c4065a22a1a..a62e0f29c373 100644
--- a/core/modules/node/src/Plugin/views/field/Node.php
+++ b/core/modules/node/src/Plugin/views/field/Node.php
@@ -73,7 +73,7 @@ protected function renderLink($data, ResultRow $values) {
         $this->options['alter']['make_link'] = TRUE;
         $this->options['alter']['path'] = "node/" . $this->getValue($values, 'nid');
         if (isset($this->aliases['langcode'])) {
-          $languages = language_list();
+          $languages = \Drupal::languageManager()->getLanguages();
           $langcode = $this->getValue($values, 'langcode');
           if (isset($languages[$langcode])) {
             $this->options['alter']['language'] = $languages[$langcode];
diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php
index a32298e64430..99c91db55d32 100644
--- a/core/modules/user/src/Entity/User.php
+++ b/core/modules/user/src/Entity/User.php
@@ -372,7 +372,7 @@ public function getTimeZone() {
    * {@inheritdoc}
    */
   function getPreferredLangcode($fallback_to_default = TRUE) {
-    $language_list = language_list();
+    $language_list = \Drupal::languageManager()->getLanguages();
     $preferred_langcode = $this->get('preferred_langcode')->value;
     if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
       return $language_list[$preferred_langcode]->getId();
@@ -386,7 +386,7 @@ function getPreferredLangcode($fallback_to_default = TRUE) {
    * {@inheritdoc}
    */
   function getPreferredAdminLangcode($fallback_to_default = TRUE) {
-    $language_list = language_list();
+    $language_list = \Drupal::languageManager()->getLanguages();
     $preferred_langcode = $this->get('preferred_admin_langcode')->value;
     if (!empty($preferred_langcode) && isset($language_list[$preferred_langcode])) {
       return $language_list[$preferred_langcode]->getId();
diff --git a/core/modules/user/src/Plugin/views/field/Language.php b/core/modules/user/src/Plugin/views/field/Language.php
index 59f74ccb9759..7e7c0eda7222 100644
--- a/core/modules/user/src/Plugin/views/field/Language.php
+++ b/core/modules/user/src/Plugin/views/field/Language.php
@@ -33,7 +33,7 @@ protected function renderLink($data, ResultRow $values) {
       $lang = language_default();
     }
     else {
-      $lang = language_list();
+      $lang = \Drupal::languageManager()->getLanguages();
       $lang = $lang[$data];
     }
 
diff --git a/core/modules/user/src/UserStorage.php b/core/modules/user/src/UserStorage.php
index 638dfc748e46..b51b1eec764c 100644
--- a/core/modules/user/src/UserStorage.php
+++ b/core/modules/user/src/UserStorage.php
@@ -15,6 +15,7 @@
 use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
 use Drupal\Core\Password\PasswordInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
@@ -45,9 +46,11 @@ class UserStorage extends SqlContentEntityStorage implements UserStorageInterfac
    *   Cache backend instance to use.
    * @param \Drupal\Core\Password\PasswordInterface $password
    *   The password hashing service.
+   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+   *   The language manager.
    */
-  public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, PasswordInterface $password) {
-    parent::__construct($entity_type, $database, $entity_manager, $cache);
+  public function __construct(EntityTypeInterface $entity_type, Connection $database, EntityManagerInterface $entity_manager, CacheBackendInterface $cache, PasswordInterface $password, LanguageManagerInterface $language_manager) {
+    parent::__construct($entity_type, $database, $entity_manager, $cache, $language_manager);
 
     $this->password = $password;
   }
@@ -61,7 +64,8 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
       $container->get('database'),
       $container->get('entity.manager'),
       $container->get('cache.entity'),
-      $container->get('password')
+      $container->get('password'),
+      $container->get('language_manager')
     );
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
index 2f0bd10d156f..2629414c1d11 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageTest.php
@@ -14,6 +14,7 @@
 use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Language\Language;
+use Drupal\Core\Language\LanguageManagerInterface;
 use Drupal\Tests\UnitTestCase;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 
@@ -79,6 +80,13 @@ class SqlContentEntityStorageTest extends UnitTestCase {
    */
   protected $cache;
 
+  /**
+   * The language manager.
+   *
+   * @var \Drupal\Core\Language\LanguageManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+   */
+  protected $languageManager;
+
   /**
    * The database connection to use.
    *
@@ -101,6 +109,10 @@ protected function setUp() {
     $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
     $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
     $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');
+    $this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
+    $this->languageManager->expects($this->any())
+      ->method('getDefaultLanguage')
+      ->will($this->returnValue(new Language(array('langcode' => 'en'))));
     $this->connection = $this->getMockBuilder('Drupal\Core\Database\Connection')
       ->disableOriginalConstructor()
       ->getMock();
@@ -334,7 +346,7 @@ public function testOnEntityTypeCreate() {
       ->will($this->returnValue($schema_handler));
 
     $storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
-      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache))
+      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager))
       ->setMethods(array('getStorageSchema'))
       ->getMock();
 
@@ -1045,7 +1057,7 @@ protected function setUpEntityStorage() {
       ->method('getBaseFieldDefinitions')
       ->will($this->returnValue($this->fieldDefinitions));
 
-    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache);
+    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager);
   }
 
   /**
@@ -1122,7 +1134,7 @@ public function testLoadMultipleNoPersistentCache() {
       ->method('set');
 
     $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
-      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache))
+      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager))
       ->setMethods(array('getFromStorage'))
       ->getMock();
     $entity_storage->expects($this->once())
@@ -1172,7 +1184,7 @@ public function testLoadMultiplePersistentCacheMiss() {
       ->with($key, $entity, CacheBackendInterface::CACHE_PERMANENT, array($this->entityTypeId . '_values', 'entity_field_info'));
 
     $entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
-      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache))
+      ->setConstructorArgs(array($this->entityType, $this->connection, $this->entityManager, $this->cache, $this->languageManager))
       ->setMethods(array('getFromStorage'))
       ->getMock();
     $entity_storage->expects($this->once())
@@ -1227,7 +1239,7 @@ public function testHasData() {
       ->method('getBaseFieldDefinitions')
       ->will($this->returnValue($this->fieldDefinitions));
 
-    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache);
+    $this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityManager, $this->cache, $this->languageManager);
 
     $result = $this->entityStorage->hasData();
 
-- 
GitLab