Problem/Motivation
The global language_list() function is deprecated and should not be used. See #2205673: [META] Remove all @deprecated functions marked "remove before 8.0".
Proposed resolution
Only the function exists, the usages should be removed.
Remaining tasks
Commit.
User interface changes
None.
API changes
None.
Original report by @a_thakur
Comment | File | Size | Author |
---|---|---|---|
#84 | interdiff-2328293-82-84.txt | 948 bytes | ashutoshsngh |
#84 | usage-language-list-2328293-84.patch | 30 KB | ashutoshsngh |
#61 | usage-language-list-2328293-61.patch | 30.07 KB | ianthomas_uk |
#61 | interdiff-60-61.txt | 4.82 KB | ianthomas_uk |
Comments
Comment #1
a_thakur CreditAttribution: a_thakur commentedPlease find the attached file which removes the function.
Result of grep
Comment #5
sidharthapStill we have some places where this function used near about 20 files on fresh D8 instance.
Thanks
Sidhartha
Comment #6
JeroenTI will work on this @ DUG Belgium.
Comment #7
JeroenTComment #8
keopxRemove function and other lines to used language_list function.
Comment #10
keopxMissing a function.
Comment #11
plopescHello @keopx
Thank you for your patch, it is good and tests are passing.
Here you have some nitpicks that will help to improve the final code:
You can inject \Drupal::LanguageManager as a dependency. You can see
Drupal\Core\Config\Entity\ConfigEntityStorage
as an example.You are calling
\Drupal::languageManager()->getLanguages();
three times in the same method. You can extract it to a variable and reuse it.You can inject
$this->languageManager
as a dependency.You can use
$this->languageManager->getLanguages();
here.Same as above.
You can inject
$this->languageManager
as a dependency.You are calling
\Drupal::languageManager()
twice in the same function. You can extract it to a variable and reuse it.You can use
$this->languageManager
here.Same as above.
Thank you again for your time.
Comment #12
keopxreroll patch
Comment #13
keopxComment #15
keopxreroll
Comment #17
keopxAdd LanguageManagerInterface and this variable.
Comment #18
keopxComment #20
keopxreroll
Comment #22
keopxI don't understand correctly problem...
Comment #24
JeroenTHi Keopx,
Thank you for your patch.
I did a review of your patch and I think i found the error :
1. In Core/modules/comment/src/CommentStorage.php
This class also extends from the SqlContentEntityManager, so you should also pass the language_manager in the parent::__construct function.
2. The same for core/modules/user/src/UserStorage.php
3.
In the createInstance function in files userStorage, CommentStorage and SqlContentEntityManager instead of using \Drupal::languageManager() you should use $container->get('language_manager').
4.There are some whitespaces issues in your patch :
/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityManager.php line 124 and 141
/core/lib/Drupal/Core/Session/UserSession.php line 105
For more information, visit https://www.drupal.org/coding-standards#indenting
Comment #25
keopxHi,
Thanks for review patch.
This file doesn't exist /core/lib/Drupal/Core/Entity/Sql/SqlContentEntityManager.php
Yes, I've configured IDE with coding standards, but I think didn't do some actions when format.
Comment #27
keopxThe last patch works fine, but doesn't pass test.
So, I do interdiff between patch #2328293-9: Remove usage of language_list() and #2328293-25: Remove usage of language_list().
Comment #28
keopxHere my new patch.
Comment #30
plopescHi keopx, we are closer now :)
Just some coding standards and nitpicks.
Minor: trailing whitespace.
You need to add the $language_manager param to the docblock.
Trailing whitespace
LanguageInterface::STATE_CONFIGURABLE is the default value for $flags parameter, so you can call to
$language_manager->getLanguages()
Trailing whitespace
You can inject LanguageManager here.
You can remove the
LanguageInterface::STATE_CONFIGURABLE
parameterApart from that, your last patch is failing because you have to take into account that
Drupal\comment\CommentStorage
andDrupal\user\UserStorage
extends\Drupal\Core\Entity\Sql\SqlContentEntityStorage
and overrides the constructor. So you have to include the language_manager in those classes.Here you have an example for
CommentStorage
:Hope this helps. Thank you for your effort!
Comment #31
keopxReroll
I think that is not possible.
6.
You can inject LanguageManager here.
Comment #33
keopxI need to change unit test to add new variable languageManager.
Changes works fine, but construct need this variable and unit test doesn't have.
Comment #34
plopescCongrats keopx, your patch looks really good :)
To get all the things sorted out, I think you should inject LanguageManager as a dependency in
\Drupal\language\Form\NegotiationUrlForm
. It is injected in all the other forms.I will take a look at the test changes later.
PS: An interdiff would be very appreciated to make the patch revision easier.
Thank you again!
Comment #35
keopxHere interdiff and new patch.
Comment #36
plopescHello, your improvements in this patch look good.
However, I think you have to do a couple of changes in the Depencency Injection implementation in
\Drupal\language\Form\NegotiationUrlForm
.Given that extends from
ConfigFormBase
and you should maintain the $configFactory in the class constructor, as it is done in\Drupal\language\Form\NegotiationBrowserForm
. This property is necessary forconfig()
methodAlso in line 129 of
NegotiationUrlForm
you have a call to the static\Drupal::languageManager()->getLanguages();
that should be replaced too.Finally, patch does not apply now, so we need a re-roll here.
Thank you!
Comment #37
keopxI do changes and reroll.
Comment #39
keopxmmm the last patch passed test...
Well, I do new version, with reroll, install correctly and pass test.
:-/
Comment #40
plopescThank you @keopx.
Patch looks really good now.
You only missed the second comment in #35.
Should use the class property
$this->languageManager
instead of the static method inNegotiationUrlForm
.Apart of that, I think this patch could be RTBC'ed.
Thank you again @keopx for your time and persistence :)
Comment #41
keopxcorrect mistake
And thank @plopesc :D
Comment #42
plopescI think this is OK now
Let's see if someone else has any objection.
Comment #43
alexpottCan we remove the usages before removing the function. Also we need to link this to the change record https://www.drupal.org/node/2174591
We will then remove the function in a separate issue. This makes patch conflict resolution much easier as HEAD is less likely to break.
It'd be nice to inject this. Which means
ContentTranslationHandler
needs to extendDrupal\Core\Entity\EntityHandlerInterface
and we should just refactorcontent_translation_controller()
out of existence and use the entity manager getHandler() instead.This can be injected see
\Drupal\node\Plugin\Condition\NodeType
Comment #44
hudo CreditAttribution: hudo commentedI am working on this issue
Comment #45
hudo CreditAttribution: hudo commentedI updated points 2 and 3 in comment #43. For point 1, there are too many places that call "function language_list"
For example:
In file: \core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php (line 1220)
If I delete language_list function above, what will happen to $langcodes ??
Comment #48
JeroenTCreated straight reroll of patch in comment 41. I haven't addressed the changes as suggested by alexpott in comment 43.
Comment #49
JeroenTSo I addressed point 1 and 3 of comment 43.
I was not quite sure how to do point 2, but I will try it later today again. Patch attached.
Comment #50
JeroenTCreated follow-up issue: #2354681: Remove language_list() from bootstrap.inc
Comment #51
JeroenTAll right I think i got it. Patch attached!
Comment #54
rpayanmComment #55
ianthomas_ukThis should use an injected language managed (it did in #22), as can getPreferredAdminLangcode.
There are several changes to content_translation_controller that seem out of scope for this issue.
There's no need for a $language_manager local variable, just use $this->language_manager each time, it isn't much longer. (this probably dates from code that didn't just an injected manager)
This should be injected
I've not picked out everything I spotted, but the above comments should cover the general themes. As a rule, if you're in a class and not in a static method, you should be calling $this->languageManager. Any changes other obviously necessary to replace language_list() should be explained in the issue summary. If you're not sure how to change something, there's an earlier patch at #2225427: Remove remaining uses of deprecated language functions (mostly in object oriented code) that might help.
Comment #56
rpayanmComment #58
ianthomas_ukIt looks like we need to create a UserSession before we can get a language manager, so I guess we'll need to stick with \Drupal for now in that class.
Comment #60
ianthomas_ukTest fixes
Comment #61
ianthomas_ukNo longer needed
It doesn't look like anything will call create(). I'm not sure if we can inject services into field plugins (none of the other ones do).
Attached patch changes the above and fixes some comments. There are no other calls to language_list().
Comment #64
JeroenTCreated re-roll.
Patch attached.
Comment #65
keopxReroll patch and interdiff with changes, but not realy interdiff. Please see it.
Comment #66
keopxClear my patch, works fine @JeroenT
Comment #67
keopxWorks fine @JeroenT patch
Comment #69
JeroenTComment #70
JeroenTPatch still applies.
Comment #73
Gábor HojtsyUpdated issue summary, tagging for D8MI.
Comment #74
alexpottThe variable assignment to $language_manager here is a waste. Just do
$language_list = \Drupal::languageManager()->getLanguages()
.I think we should replace all the code in content_translation_controller with
This wrapper should be removed because it is pointless and only adds maintenance overhead but that is separate issue.
asdsa
Comment #75
ashutoshsngh CreditAttribution: ashutoshsngh commented#74 Changes
Comment #76
keopx@ashutoshsngh please, the interdiff file is good to see changes.
Do you use https://www.drupal.org/node/2328293#comment-9478605 patch base?
Comment #77
ashutoshsngh CreditAttribution: ashutoshsngh commentedInterdiff attached.
I have used https://www.drupal.org/node/2328293#comment-9478611 as batch base.
Comment #78
ashutoshsngh CreditAttribution: ashutoshsngh commentedComment #79
keopx@ashutoshsngh
Use #64 issue patch, because I did not add this lines.
And another thing.
Your add some non coding standars lines. Review your interdiff file. Example:
Comment #80
ashutoshsngh CreditAttribution: ashutoshsngh commentedFixed all spaces issues according to #79.
Comment #81
alexpottStill need to fix getPreferredAdminLangcode()
Comment #82
rpayanmComment #83
ianthomas_ukI compared #64 and #82. Comments from #74 have been addressed, but #64 replaced a call to \Drupal in ContentTranslationHandler line 161 that has been lost.
Other than I would have set to RTBC.
Comment #84
ashutoshsngh CreditAttribution: ashutoshsngh commentedDone
Comment #85
ianthomas_uk#84 fixes that one remaining issue, thanks.
Comment #86
alexpottBeta evaluation is in the meta issue. Committed 338e966 and pushed to 8.0.x. Thanks!
Comment #88
Gábor HojtsyAmazing, thanks!
Comment #90
janoka CreditAttribution: janoka commentedMarked #2328463: Language condition plugin needs LanguageManager injected, unit tests added as duplicate of this issue.