Issue #2340667 by alexpott, martin107: Protect Drupal\Core\Language\Language::id, and use getId().

From: Pedro Lozano <peterlozano@gmail.com>


---
 .../Core/Page/DefaultHtmlFragmentRenderer.php      |    2 +-
 .../aggregator/src/Tests/FeedLanguageTest.php      |    6 +++---
 core/modules/book/book.module                      |    2 +-
 core/modules/book/src/BookManager.php              |    4 ++--
 .../ckeditor/src/Plugin/Editor/CKEditor.php        |    4 ++--
 .../comment/src/Tests/CommentTokenReplaceTest.php  |   10 +++++-----
 .../file/src/Tests/FileTokenReplaceTest.php        |   12 ++++++------
 core/modules/filter/filter.module                  |    4 ++--
 core/modules/language/language.module              |    4 ++--
 .../src/Tests/LanguageConfigurationElementTest.php |    2 +-
 core/modules/locale/locale.module                  |   12 ++++++------
 core/modules/search/search.pages.inc               |    2 +-
 .../src/Tests/StatisticsTokenReplaceTest.php       |    2 +-
 core/modules/system/language.api.php               |    4 ++--
 core/modules/system/src/Tests/Mail/MailTest.php    |    2 +-
 .../taxonomy/src/Tests/TokenReplaceTest.php        |   10 +++++-----
 core/modules/user/src/AccountForm.php              |    4 ++--
 .../user/src/Tests/UserRegistrationTest.php        |    4 ++--
 .../user/src/Tests/UserTokenReplaceTest.php        |   14 +++++++-------
 19 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
index 8711ee2..320d9c6 100644
--- a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
+++ b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php
@@ -100,7 +100,7 @@ public function preparePage(HtmlPage $page, &$page_array) {
     // HTML element attributes.
     $language_interface = $this->languageManager->getCurrentLanguage();
     $html_attributes = $page->getHtmlAttributes();
-    $html_attributes['lang'] = $language_interface->id;
+    $html_attributes['lang'] = $language_interface->getId();
     $html_attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr';
 
     $this->setDefaultMetaTags($page);
diff --git a/core/modules/aggregator/src/Tests/FeedLanguageTest.php b/core/modules/aggregator/src/Tests/FeedLanguageTest.php
index 0d4e481..09c608c 100644
--- a/core/modules/aggregator/src/Tests/FeedLanguageTest.php
+++ b/core/modules/aggregator/src/Tests/FeedLanguageTest.php
@@ -56,8 +56,8 @@ public function testFeedLanguage() {
     $feeds[2] = $this->createFeed(NULL, array('langcode' => $this->langcodes[2]));
 
     // Make sure that the language has been assigned.
-    $this->assertEqual($feeds[1]->language()->id, $this->langcodes[1]);
-    $this->assertEqual($feeds[2]->language()->id, $this->langcodes[2]);
+    $this->assertEqual($feeds[1]->language()->getId(), $this->langcodes[1]);
+    $this->assertEqual($feeds[2]->language()->getId(), $this->langcodes[2]);
 
     // Create example nodes to create feed items from and then update the feeds.
     $this->createSampleNodes();
@@ -70,7 +70,7 @@ public function testFeedLanguage() {
       $items = entity_load_multiple_by_properties('aggregator_item', array('fid' => $feed->id()));
       $this->assertTrue(count($items) > 0, 'Feed items were created.');
       foreach ($items as $item) {
-        $this->assertEqual($item->language()->id, $feed->language()->id);
+        $this->assertEqual($item->language()->getId(), $feed->language()->getId());
       }
     }
   }
diff --git a/core/modules/book/book.module b/core/modules/book/book.module
index dc20b1d..c0db354 100644
--- a/core/modules/book/book.module
+++ b/core/modules/book/book.module
@@ -472,7 +472,7 @@ function template_preprocess_book_export_html(&$variables) {
 
   // HTML element attributes.
   $attributes = array();
-  $attributes['lang'] = $language_interface->id;
+  $attributes['lang'] = $language_interface->getId();
   $attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr';
   $variables['html_attributes'] = new Attribute($attributes);
 }
diff --git a/core/modules/book/src/BookManager.php b/core/modules/book/src/BookManager.php
index efab641..8f2ab35 100644
--- a/core/modules/book/src/BookManager.php
+++ b/core/modules/book/src/BookManager.php
@@ -443,7 +443,7 @@ public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) {
     $nid = isset($link['nid']) ? $link['nid'] : 0;
     // Generate a cache ID (cid) specific for this $bid, $link, $language, and
     // depth.
-    $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->id . ':' . (int) $max_depth;
+    $cid = 'book-links:' . $bid . ':all:' . $nid . ':' . $language_interface->getId() . ':' . (int) $max_depth;
 
     if (!isset($tree[$cid])) {
       // If the tree data was not in the static cache, build $tree_parameters.
@@ -596,7 +596,7 @@ protected function doBookTreeBuild($bid, array $parameters = array()) {
     if (isset($parameters['expanded'])) {
       sort($parameters['expanded']);
     }
-    $tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface->id . ':' . hash('sha256', serialize($parameters));
+    $tree_cid = 'book-links:' . $bid . ':tree-data:' . $language_interface->getId() . ':' . hash('sha256', serialize($parameters));
 
     // If we do not have this tree in the static cache, check {cache_data}.
     if (!isset($trees[$tree_cid])) {
diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
index 6d92f98..0762728 100644
--- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -271,8 +271,8 @@ public function getJSSettings(EditorEntity $editor) {
     // Map the interface language code to a CKEditor translation.
     $ckeditor_langcodes = $this->getLangcodes();
     $language_interface = $this->languageManager->getCurrentLanguage();
-    if (isset($ckeditor_langcodes[$language_interface->id])) {
-      $display_langcode = $ckeditor_langcodes[$language_interface->id];
+    if (isset($ckeditor_langcodes[$language_interface->getId()])) {
+      $display_langcode = $ckeditor_langcodes[$language_interface->getId()];
     }
 
     // Next, set the most fundamental CKEditor settings.
diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
index 76eca29..c3699ae 100644
--- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
+++ b/core/modules/comment/src/Tests/CommentTokenReplaceTest.php
@@ -59,8 +59,8 @@ function testCommentTokenReplacement() {
     $tests['[comment:body]'] = $comment->comment_body->processed;
     $tests['[comment:url]'] = $comment->url('canonical', $url_options + array('fragment' => 'comment-' . $comment->id()));
     $tests['[comment:edit-url]'] = $comment->url('edit-form', $url_options);
-    $tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->id);
-    $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->id);
+    $tests['[comment:created:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getCreatedTime(), 2, $language_interface->getId());
+    $tests['[comment:changed:since]'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $comment->getChangedTime(), 2, $language_interface->getId());
     $tests['[comment:parent:cid]'] = $comment->hasParentComment() ? $comment->getParentComment()->id() : NULL;
     $tests['[comment:parent:title]'] = String::checkPlain($parent_comment->getSubject());
     $tests['[comment:node:nid]'] = $comment->getCommentedEntityId();
@@ -72,7 +72,7 @@ function testCommentTokenReplacement() {
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized comment token %token replaced.', array('%token' => $input)));
     }
 
@@ -89,7 +89,7 @@ function testCommentTokenReplacement() {
     $tests['[comment:author:name]'] = $this->admin_user->getUsername();
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->id, 'sanitize' => FALSE));
+      $output = $token_service->replace($input, array('comment' => $comment), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
       $this->assertEqual($output, $expected, format_string('Unsanitized comment token %token replaced.', array('%token' => $input)));
     }
 
@@ -105,7 +105,7 @@ function testCommentTokenReplacement() {
     $tests['[node:comment-count-new]'] = 2;
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('entity' => $node, 'node' => $node), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Node comment token %token replaced.', array('%token' => $input)));
     }
   }
diff --git a/core/modules/file/src/Tests/FileTokenReplaceTest.php b/core/modules/file/src/Tests/FileTokenReplaceTest.php
index 36fe888..450c778 100644
--- a/core/modules/file/src/Tests/FileTokenReplaceTest.php
+++ b/core/modules/file/src/Tests/FileTokenReplaceTest.php
@@ -48,10 +48,10 @@ function testFileTokenReplacement() {
     $tests['[file:mime]'] = String::checkPlain($file->getMimeType());
     $tests['[file:size]'] = format_size($file->getSize());
     $tests['[file:url]'] = String::checkPlain(file_create_url($file->getFileUri()));
-    $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->id);
-    $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->id);
-    $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->id);
-    $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->id);
+    $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
+    $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
+    $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId());
+    $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[file:owner]'] = String::checkPlain(user_format_name($this->admin_user));
     $tests['[file:owner:uid]'] = $file->getOwnerId();
 
@@ -59,7 +59,7 @@ function testFileTokenReplacement() {
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input)));
     }
 
@@ -70,7 +70,7 @@ function testFileTokenReplacement() {
     $tests['[file:size]'] = format_size($file->getSize());
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->id, 'sanitize' => FALSE));
+      $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
       $this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', array('%token' => $input)));
     }
   }
diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module
index 9040b56..80c690e 100644
--- a/core/modules/filter/filter.module
+++ b/core/modules/filter/filter.module
@@ -133,13 +133,13 @@ function filter_formats(AccountInterface $account = NULL) {
   // All available formats are cached for performance.
   if (!isset($formats['all'])) {
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
-    if ($cache = \Drupal::cache()->get("filter_formats:{$language_interface->id}")) {
+    if ($cache = \Drupal::cache()->get("filter_formats:{$language_interface->getID()}")) {
       $formats['all'] = $cache->data;
     }
     else {
       $formats['all'] = \Drupal::entityManager()->getStorage('filter_format')->loadByProperties(array('status' => TRUE));
       uasort($formats['all'], 'Drupal\Core\Config\Entity\ConfigEntityBase::sort');
-      \Drupal::cache()->set("filter_formats:{$language_interface->id}", $formats['all'], Cache::PERMANENT, array('filter_formats'));
+      \Drupal::cache()->set("filter_formats:{$language_interface->getID()}", $formats['all'], Cache::PERMANENT, array('filter_formats'));
     }
   }
 
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index 40b9bfa..f5dda41 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -305,7 +305,7 @@ function language_get_default_langcode($entity_type, $bundle) {
       break;
 
     case 'current_interface':
-      $default_value = $language_interface->id;
+      $default_value = $language_interface->getId();
       break;
 
     case 'authors_default':
@@ -315,7 +315,7 @@ function language_get_default_langcode($entity_type, $bundle) {
         $default_value = $language_code;
       }
       else {
-        $default_value = $language_interface->id;
+        $default_value = $language_interface->getId();
       }
       break;
   }
diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
index 6815955..6dd1b8a 100644
--- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
+++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
@@ -77,7 +77,7 @@ public function testDefaultLangcode() {
     language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_show' => TRUE));
     $langcode = language_get_default_langcode('custom_type', 'custom_bundle');
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
-    $this->assertEqual($langcode, $language_interface->id);
+    $this->assertEqual($langcode, $language_interface->getId());
 
     // Site's default.
     $old_default = \Drupal::languageManager()->getDefaultLanguage();
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 40934de..250aaed 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -296,7 +296,7 @@ function locale_get_plural($count, $langcode = NULL) {
   // individually for each language.
   $plural_indexes = &drupal_static(__FUNCTION__ . ':plurals', array());
 
-  $langcode = $langcode ? $langcode : $language_interface->id;
+  $langcode = $langcode ? $langcode : $language_interface->getId();
 
   if (!isset($plural_indexes[$langcode][$count])) {
     // Retrieve and statically cache the plural formulas for all languages.
@@ -518,11 +518,11 @@ function locale_js_translate(array $files = array()) {
   }
 
   // If necessary, rebuild the translation file for the current language.
-  if (!empty($parsed['refresh:' . $language_interface->id])) {
+  if (!empty($parsed['refresh:' . $language_interface->getId()])) {
     // Don't clear the refresh flag on failure, so that another try will
     // be performed later.
     if (_locale_rebuild_js()) {
-      unset($parsed['refresh:' . $language_interface->id]);
+      unset($parsed['refresh:' . $language_interface->getId()]);
     }
     // Store any changes after refresh was attempted.
     \Drupal::state()->set('system.javascript_parsed', $parsed);
@@ -536,9 +536,9 @@ function locale_js_translate(array $files = array()) {
   // Add the translation JavaScript file to the page.
   $locale_javascripts = \Drupal::state()->get('locale.translation.javascript') ?: array();
   $translation_file = NULL;
-  if (!empty($files) && !empty($locale_javascripts[$language_interface->id])) {
+  if (!empty($files) && !empty($locale_javascripts[$language_interface->getId()])) {
     // Add the translation JavaScript file to the page.
-    $translation_file = $dir . '/' . $language_interface->id . '_' . $locale_javascripts[$language_interface->id] . '.js';
+    $translation_file = $dir . '/' . $language_interface->getId() . '_' . $locale_javascripts[$language_interface->getId()] . '.js';
   }
   return $translation_file;
 }
@@ -732,7 +732,7 @@ function locale_preprocess_node(&$variables) {
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
 
     $node_language = $variables['node']->language();
-    if ($node_language->id != $language_interface->id) {
+    if ($node_language->id != $language_interface->getId()) {
       // If the node language was different from the page language, we should
       // add markup to identify the language. Otherwise the page language is
       // inherited.
diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc
index 6590b90..4c84c84 100644
--- a/core/modules/search/search.pages.inc
+++ b/core/modules/search/search.pages.inc
@@ -37,7 +37,7 @@ function template_preprocess_search_result(&$variables) {
   $result = $variables['result'];
   $variables['url'] = check_url($result['link']);
   $variables['title'] = String::checkPlain($result['title']);
-  if (isset($result['language']) && $result['language'] != $language_interface->id && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
+  if (isset($result['language']) && $result['language'] != $language_interface->getId() && $result['language'] != LanguageInterface::LANGCODE_NOT_SPECIFIED) {
     $variables['title_attributes']['lang'] = $result['language'];
     $variables['content_attributes']['lang'] = $result['language'];
   }
diff --git a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php
index 05b6aab..d481f01 100644
--- a/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php
+++ b/core/modules/statistics/src/Tests/StatisticsTokenReplaceTest.php
@@ -49,7 +49,7 @@ function testStatisticsTokenReplacement() {
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->id));
+      $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', array('%token' => $input)));
     }
   }
diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php
index f52e22d..dc491fe 100644
--- a/core/modules/system/language.api.php
+++ b/core/modules/system/language.api.php
@@ -108,8 +108,8 @@
 function hook_language_switch_links_alter(array &$links, $type, $path) {
   $language_interface = \Drupal::languageManager()->getCurrentLanguage();
 
-  if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->id])) {
-    foreach ($links[$language_interface->id] as $link) {
+  if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->getId()])) {
+    foreach ($links[$language_interface->getId()] as $link) {
       $link['attributes']['class'][] = 'active-language';
     }
   }
diff --git a/core/modules/system/src/Tests/Mail/MailTest.php b/core/modules/system/src/Tests/Mail/MailTest.php
index a4dcf5f..78ebf24 100644
--- a/core/modules/system/src/Tests/Mail/MailTest.php
+++ b/core/modules/system/src/Tests/Mail/MailTest.php
@@ -60,7 +60,7 @@ public function testCancelMessage() {
     \Drupal::state()->set('system.test_mail_collector', array());
 
     // Send a test message that simpletest_mail_alter should cancel.
-    drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->id);
+    drupal_mail('simpletest', 'cancel_test', 'cancel@example.com', $language_interface->getId());
     // Retrieve sent message.
     $captured_emails = \Drupal::state()->get('system.test_mail_collector');
     $sent_message = end($captured_emails);
diff --git a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php
index d343995..f25591b 100644
--- a/core/modules/taxonomy/src/Tests/TokenReplaceTest.php
+++ b/core/modules/taxonomy/src/Tests/TokenReplaceTest.php
@@ -91,7 +91,7 @@ function testTaxonomyTokenReplacement() {
     $tests['[term:vocabulary:name]'] = String::checkPlain($this->vocabulary->name);
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
     }
 
@@ -111,7 +111,7 @@ function testTaxonomyTokenReplacement() {
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
     }
 
@@ -122,7 +122,7 @@ function testTaxonomyTokenReplacement() {
     $tests['[term:vocabulary:name]'] = $this->vocabulary->name;
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->id, 'sanitize' => FALSE));
+      $output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
       $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
     }
 
@@ -138,7 +138,7 @@ function testTaxonomyTokenReplacement() {
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
     }
 
@@ -147,7 +147,7 @@ function testTaxonomyTokenReplacement() {
     $tests['[vocabulary:description]'] = $this->vocabulary->description;
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->id, 'sanitize' => FALSE));
+      $output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
       $this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
     }
   }
diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php
index 13e60a2..e615aa5 100644
--- a/core/modules/user/src/AccountForm.php
+++ b/core/modules/user/src/AccountForm.php
@@ -240,9 +240,9 @@ public function form(array $form, FormStateInterface $form_state) {
       );
     }
 
-    $user_preferred_langcode = $register ? $language_interface->id : $account->getPreferredLangcode();
+    $user_preferred_langcode = $register ? $language_interface->getId() : $account->getPreferredLangcode();
 
-    $user_preferred_admin_langcode = $register ? $language_interface->id : $account->getPreferredAdminLangcode(FALSE);
+    $user_preferred_admin_langcode = $register ? $language_interface->getId() : $account->getPreferredAdminLangcode(FALSE);
 
     // Is the user preferred language added?
     $user_language_added = FALSE;
diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php
index f6a34bd..a1f189d 100644
--- a/core/modules/user/src/Tests/UserRegistrationTest.php
+++ b/core/modules/user/src/Tests/UserRegistrationTest.php
@@ -182,8 +182,8 @@ function testRegistrationDefaultValues() {
     $this->assertTrue(($new_user->getCreatedTime() > REQUEST_TIME - 20 ), 'Correct creation time.');
     $this->assertEqual($new_user->isActive(), $config_user_settings->get('register') == USER_REGISTER_VISITORS ? 1 : 0, 'Correct status field.');
     $this->assertEqual($new_user->getTimezone(), $config_system_date->get('timezone.default'), 'Correct time zone field.');
-    $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->id, 'Correct language field.');
-    $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->id, 'Correct preferred language field.');
+    $this->assertEqual($new_user->langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct language field.');
+    $this->assertEqual($new_user->preferred_langcode->value, \Drupal::languageManager()->getDefaultLanguage()->getId(), 'Correct preferred language field.');
     $this->assertEqual($new_user->init->value, $mail, 'Correct init field.');
   }
 
diff --git a/core/modules/user/src/Tests/UserTokenReplaceTest.php b/core/modules/user/src/Tests/UserTokenReplaceTest.php
index 3d9e8fe..897e2aa 100644
--- a/core/modules/user/src/Tests/UserTokenReplaceTest.php
+++ b/core/modules/user/src/Tests/UserTokenReplaceTest.php
@@ -59,17 +59,17 @@ function testUserTokenReplacement() {
     $tests['[user:mail]'] = String::checkPlain($account->getEmail());
     $tests['[user:url]'] = $account->url('canonical', $url_options);
     $tests['[user:edit-url]'] = $account->url('edit-form', $url_options);
-    $tests['[user:last-login]'] = format_date($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->id);
-    $tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->id);
-    $tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->id);
-    $tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->id);
+    $tests['[user:last-login]'] = format_date($account->getLastLoginTime(), 'medium', '', NULL, $language_interface->getId());
+    $tests['[user:last-login:short]'] = format_date($account->getLastLoginTime(), 'short', '', NULL, $language_interface->getId());
+    $tests['[user:created]'] = format_date($account->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
+    $tests['[user:created:short]'] = format_date($account->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[current-user:name]'] = String::checkPlain(user_format_name($global_account));
 
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id));
+      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId()));
       $this->assertEqual($output, $expected, format_string('Sanitized user token %token replaced.', array('%token' => $input)));
     }
 
@@ -79,7 +79,7 @@ function testUserTokenReplacement() {
     $tests['[current-user:name]'] = user_format_name($global_account);
 
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id, 'sanitize' => FALSE));
+      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
       $this->assertEqual($output, $expected, format_string('Unsanitized user token %token replaced.', array('%token' => $input)));
     }
 
@@ -91,7 +91,7 @@ function testUserTokenReplacement() {
     // Generate tokens with interface language.
     $link = \Drupal::url('user.page', [], array('absolute' => TRUE));
     foreach ($tests as $input => $expected) {
-      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->id, 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE));
+      $output = $token_service->replace($input, array('user' => $account), array('langcode' => $language_interface->getId(), 'callback' => 'user_mail_tokens', 'sanitize' => FALSE, 'clear' => TRUE));
       $this->assertTrue(strpos($output, $link) === 0, 'Generated URL is in interface language.');
     }
 
