At the moment we have very few usages of Drupal::service('language_manager') throughout core, but as soon as #1862202: Objectify the language system lands this number will explode, AAMOF all occurrences of language_list() will be deprectaed in favor of direct calls to the language manager.
This seems a good time to add the helper Drupal::languageManager() method.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | language-service_wrapper-2020249-1.patch | 1.54 KB | plach |
Comments
Comment #1
plachAnd here it is.
Comment #2
ParisLiakos commentedmakes sense
Comment #3
berdirAgreed. And this is fine to get in.
That said, Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE) is still quite ugly, among other things because you need a use for Language and we went to great length to avoid that you have to use Drupal in procedural code. Of which we have less and less but still a fair bit and contrib will have a lot.
So, given that we have constants for those anyway, what about introducing helper methods (in a follow-up issue, of course) for those hardcoded types: Drupal::languageManager()->getInterfaceLanguage()?
Comment #4
alexpottCommitted 6012988 and pushed to 8.x. Thanks!
Comment #5
berdirOpened #2020301: Make the $type parameter of LanguageManager::getLanguage() optional to improve DX for that.
Comment #6
gábor hojtsyComment #7.0
(not verified) commentedUpdated issue summary.