Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE) is a bit ugly to use.
Let's add helper methods for the hardcoded types (the Language::TYPE_* constants), e.g. getInterfaceLanguage(). Method should be very simple, just call getLanguage($type) internally.
This saves a use of the Language class where we just need it for that and is much easier to understand with method autocompletion.
Comment | File | Size | Author |
---|---|---|---|
#14 | language-type_ui-2020301-7.patch | 916 bytes | Berdir |
#7 | language-type_ui-2020301-7.do_not_test.patch | 916 bytes | plach |
#4 | language-type_ui-2020301-3.do_not_test.patch | 842 bytes | plach |
#3 | language-type_ui-2020301-2.patch | 616 bytes | plach |
Comments
Comment #1
plachI was thinking about something similar too, but since most calls refer to the interface language, what about just making the
$type
parameter optional and the defaulting to it? Among the rest this would avoid special-casing the three core language types, since contrib ones couldn't have a dedicated method.Things would look like this in (all?) most core procedural code:
Comment #2
BerdirThat's fine with me as well. The only disadvantage that I can come up with is that people might be less aware of the fact that there can be multiple languages.. interface, content, ...But as you said, in 9x% of the cases, you want the interface language and the people that need to explicitly access the content language or so probably know what they are doing :)
That makes this issue even easier, just add a default value to the method.
Comment #3
plachCould be as easy as this, if we don't want to piss everyone off with yet another language patch screwing all the others on the queue ;)
Comment #4
plachFixing PHP docs would be even better ;)
Comment #5
plachI completely agree with #2, reached the same conclusions.
Comment #6
BerdirI think the reference here should be fully qualified even when it's in the same namespace.
Comment #7
plachrrright
Comment #9
Berdir#3: language-type_ui-2020301-2.patch queued for re-testing.
Comment #10
plachI knew you were kidding me, bot :)
Comment #11
BerdirRTBC from my side. Maybe Gabor wants to RTBC it, so that we have a third person in here?
Also, a bit unusual to use do-not-test for actual patches, even if they just change documentation. I can cancel patches if you ping me in IRC :) Or a few other people.
Comment #12
plachSounds good, putting on sprint for him.
noted :)
Comment #13
Gábor Hojtsy#7 should be reposted so testbot tests it. That prior versions passed earlier (with identical code changes) does not actually prove that it would currently pass.
Comment #14
BerdirRe-uploading that patch. All credit goes to @plach :)
Comment #15
Gábor HojtsyLooks like a good DX improvement.
Comment #16
BerdirDo we need a follow-up to remove the argument from existing calls? We need one to convert language() to Drupal::languageManager()->getLanguage() anyway, can do it as part of that I guess?
Comment #17
plachCrosspost, I think.
Yep, makes sense.
Comment #18
catchPatch looks fine, as does converting all the calls in a follow-up. Committed/pushed to 8.x, thanks!
Comment #19
Berdirhttps://drupal.org/node/1450578 looks quite outdated and should be updated, not just for this change but also Drupal::languageManager(). There might be additional change notices related to this as well..
Comment #20
elachlan CreditAttribution: elachlan commentedI changed it a little bit to what I was told in IRC. Thanks Berdir!!
Comment #21
Gábor HojtsyWhat other changes are needed? https://drupal.org/node/1450578/revisions/view/2574684/2733887 was the change for reference.
Comment #22
plachWe might want to note that different language types can be passed to
LanguageManager::getLanguage()
.Comment #23
BerdirYes, there's still a reference to the old constant in the description and we should probably list the types that core supports as plach said. Searching for the constant, there are a also two other change notices that should be updated: https://drupal.org/list-changes?keywords_description=LANGUAGE_TYPE_INTER...
Comment #24
BerdirDone: https://drupal.org/node/1450578/revisions/view/2733907/2734655
Also updated the references in the other two.
Comment #25
plachLooks good, thanks.
Comment #26
plachComment #27
Gábor Hojtsy