Problem/Motivation

language() and global $language are now deprecated.

Proposed resolution

Use \Drupal::languageManager()->getCurrentLanguage($type) to replace language($type)
Use \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_INTERFACE) to replace global $language

Read more: https://drupal.org/node/2174591 and https://drupal.org/node/1450578

CommentFileSizeAuthor
#45 interdiff-2070369-43-45.txt749 bytesherom
#45 remove-language-2070369-45.patch40.74 KBherom
#43 remove-language-2070369-43.patch40.09 KBjeroent
#40 interdiff-2070369-38-40.txt769 bytesherom
#40 remove-language-2070369-40.patch40.2 KBherom
#38 interdiff-2070369-35-38.txt2.73 KBherom
#38 remove-language-2070369-38.patch40.95 KBherom
#35 interdiff-2070369-33-35.txt720 bytesinternetdevels
#35 drupal8.language.module-remove_deprecated_function_language-2070369-35.patch42.46 KBinternetdevels
#33 drupal8.language.module-remove_deprecated_function_language-2070369-33.patch41.62 KBinternetdevels
#29 drupal8.language.module-remove_deprecated_function_language-2070369-29.patch46.85 KBmac_weber
#28 drupal8.language.module-remove_deprecated_function_language-2070369-28.patch34.56 KBmac_weber
#23 drupal8.language.module-remove_deprecated_function_language-2070369-23.patch7.91 KBbdgreen
#18 drupal8.language.module-remove_deprecated_function_language-2070369-18.patch4.22 KBbdgreen
#14 drupal8.language.module-remove_deprecated_function_language-2070369-14.patch5.56 KBbdgreen
#10 drupal8.language.module-remove_deprecated_function_language-2070369-10.patch7.91 KBbdgreen
#8 drupal8.language.module-remove_deprecated_function_language-2070369-8.patch6.17 KBmac_weber
#7 drupal8.language.module-remove_deprecated_function_language-2070369-7.patch5.52 KBsidharthap
#7 interdiff-2070369-1-7.txt4.18 KBsidharthap
#4 drupal8.language.module-remove_deprecated_function_language-2070369-4.patch5.39 KBsidharthap
#1 drupal8.language.module-remove_deprecated_function_language-2070369-1.patch4.9 KBmac_weber

Comments

mac_weber’s picture

mac_weber’s picture

Status: Active » Needs review

Status: Needs review » Needs work
sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new5.39 KB

Hope it will pass.

mac_weber’s picture

mac_weber’s picture

Status: Needs review » Needs work

@sidharthap there is one last call you forgot to convert in your patch.

+++ b/core/modules/language/tests/language_test/language_test.module
@@ -15,8 +15,8 @@
-  if (isset(language(Language::TYPE_INTERFACE)->id) && isset(language(Language::TYPE_INTERFACE)->method_id)) {
-    drupal_set_message(t('Language negotiation method: @name', array('@name' => language(Language::TYPE_INTERFACE)->method_id)));
+  if (isset(Drupal::languageManager()->getLanguage()->id) && isset(Drupal::languageManager()->getLanguage()->method_id)) {
+    drupal_set_message(t('Language negotiation method: @name', array('@name' => Drupal::languageManager()->getLanguage()->method_id)));

There is also a line which I cannot figure out why you got rid of. And if there is any reason for deleting it, it may be out of the scope of this issue.

+++ b/core/modules/language/tests/language_test/language_test.module
@@ -96,9 +96,8 @@ function language_test_language_negotiation_info_alter(array &$negotiation_info)
-  print_r(language_types_get_all());

Our patches look almost the same, I wonder if your patch passes the tests only because of this extra line you deleted. Please send an interdiff with next patch.

sidharthap’s picture

Status: Needs work » Needs review
StatusFileSize
new4.18 KB
new5.52 KB

Thank you @Mac_Weber for reviewing. here is the new patch and indiff txt file.

mac_weber’s picture

You created the interdiff against HEAD, not against the first patch. Well, I think I realized the problem on the first patch, some calls are missing the leading backslash, such as \Drupal::languageManager()

I also suggest you using git format-patch for creating the patches, yet it is not necessary: https://drupal.org/node/1054616

    +++ b/core/modules/language/tests/language_test/language_test.module
    @@ -96,9 +96,8 @@ function language_test_language_negotiation_info_alter(array &$negotiation_info)
    -  print_r(language_types_get_all());
    

You are still deleting this line. Which is out of the scope of this patch.

Sending correct patch, which just fixes the print_r(language_types_get_all()); on the patch at #7

areke’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

This patch doesn't apply anymore, so it needs to be re-rolledc.

bdgreen’s picture

bdgreen’s picture

herom’s picture

Status: Needs work » Needs review

let's test.

Status: Needs review » Needs work
bdgreen’s picture

Reviewed my reroll patch #10 - d'oh - and submitted a new reroll from patch #8.

bdgreen’s picture

Status: Needs work » Needs review

Submitted for testing

bdgreen’s picture

Status: Needs work » Needs review

Submitted for testing

herom’s picture

Status: Needs review » Needs work

@bdgreen, all Drupal:: references should be prefixed with a backslash. this has been standardized in core: #2053489: Standardize on \Drupal throughout core.

otherwise, good job.

bdgreen’s picture

Status: Needs work » Needs review
StatusFileSize
new4.22 KB

Thanks @herom. Corrections made.

Status: Needs review » Needs work
bdgreen’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
herom’s picture

@bdgreen this needs another reroll now.

bdgreen’s picture

Status: Needs work » Needs review
StatusFileSize
new7.91 KB

Rerolled ;)

herom’s picture

I guess you didn't reroll #18, ha? just repeat what you did at #14 and #18 on top of #23.

bdgreen’s picture

Yep. Reverted to #14, and since found two further corrections- but now waiting for test results before submitting xD

Status: Needs review » Needs work
bdgreen’s picture

Status: Needs work » Needs review
mac_weber’s picture

The last patch was fixing only one file.

@bdgreen, please make the patch files against HEAD, this will make them easier for revision.

Moreover, I've noted the first patches (including #8) have a small mistake not including the variable $type

There are many new files now that should be patched.

Sending a new one.

mac_weber’s picture

there was many other missing entries I've added in this new patch

sun’s picture

Issue tags: +@deprecated
internetdevels’s picture

Assigned: Unassigned » internetdevels
Issue summary: View changes
Issue tags: -Needs reroll

I am working on re-rolling #29 patch but I found that
LanguageManager::getLanguage was changed in #1862202: Objectify the language system and now it requires $langcode to be specified.
So, LanguageManager::getCurrentLanguage should be used instead. I.e.

should be

  $language = \Drupal::languageManager()->getCurrentLanguage();

instead of

  $language = \Drupal::languageManager()->getLanguage();
internetdevels’s picture

Assigned: internetdevels » Unassigned
Status: Needs work » Needs review
StatusFileSize
new41.62 KB

Here is re-rolled and corrected patch.
It removes all calls of the language() and function language() itself.
Actually, all calls of the language() were replaced by \Drupal::languageManager()->getCurrentLanguage() according to https://drupal.org/node/2174591.

Status: Needs review » Needs work
internetdevels’s picture

Status: Needs work » Needs review
StatusFileSize
new42.46 KB
new720 bytes

Seems I missed one place to replace language()

ianthomas_uk’s picture

Issue summary: View changes

Updated the summary following API changes.

+++ b/core/lib/Drupal/Core/Routing/UrlGeneratorInterface.php
@@ -55,7 +55,7 @@
+   *     obtained from \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_URL).

Will it? I had a quick look at the implementation of this and I think it's already using an injected object. I don't think this is something we can specify at the interface level so we should just remove the sentence. Similar comments appear elsewhere in the interface and in Drupal.php (the line is also over 80 characters BTW).

+++ b/core/includes/entity.inc
@@ -120,7 +120,7 @@ function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = N
-    $langcode = language(Language::TYPE_INTERFACE)->id;
+    $langcode = \Drupal::languageManager()->getCurrentLanguage()->id;

We've lost Language::TYPE_INTERFACE. I'm not sure if this was a deliberate choice because TYPE_INTERFACE is the default, but surely it's better to be explict. There are lots of examples of this.

+++ b/core/modules/ckeditor/ckeditor.admin.inc
@@ -20,7 +20,7 @@
+  $language_interface = \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_CONTENT);
...
-  $language_interface = language(Language::TYPE_INTERFACE);

Here we're switching from TYPE_INTERFACE to TYPE_CONTENT. If that's intentional it's out of scope (and the variable name should have been changed too.)

berdir’s picture

Status: Needs review » Needs work

First part: I'd just convert that into an actual sentence, something like "Defaults to the current language for the language type Language::TYPE_URL"?

Second part, +1 to removing the default, existing examples often specify it because there used to be no default value. The idea is that if you don't know which one you need, it's very likely the default.

ckeditor: Yep, that looks wrong, probably a wrong copy & paste?

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new40.95 KB
new2.73 KB

rerolled, and fixed points in #36.

ianthomas_uk’s picture

Status: Needs review » Needs work
+++ b/core/includes/bootstrap.inc
@@ -2072,21 +2072,6 @@ function drupal_language_initialize() {
-function language($type) {
-  return \Drupal::languageManager()->getCurrentLanguage($type);
-}

Currently we're keeping the functions themselves in, which reduces the chance of breaking HEAD and makes the eventual removal patch easier to roll back.

Other than that, this patch looks ready.

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new40.2 KB
new769 bytes

patch without removing language() function.

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

All my concerns have been addressed

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

remove-language-2070369-40.patch no longer applies.

error: patch failed: core/modules/locale/locale.module:693
error: core/modules/locale/locale.module: patch does not apply

jeroent’s picture

StatusFileSize
new40.09 KB

Created reroll.

Patch attached.

jeroent’s picture

Status: Needs work » Needs review
herom’s picture

Issue tags: -Needs reroll
StatusFileSize
new40.74 KB
new749 bytes

replacing 1 new language() call.

ianthomas_uk’s picture

Status: Needs review » Reviewed & tested by the community

reroll looks good

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

Looks like the change notice at https://drupal.org/node/2174591 covers this change and then some, so we appear to be good there.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.