Problem/Motivation
When adding new languages, they do not get a weight assigned. Locked / built-in languages get explicit weights so they are always at the end of the list, but configured languages do not get weights. This means when displaying a language list, the displayed order is different based on translations of languages at the time. That is not expected because sites usually expect languages in a fixed order.
A workaround is to hit save the language admin page once all languages are added, so that each language gets a different weight.
Beta phase evaluation
Issue category | Bug because saving should not reorder the order. |
---|---|
Issue priority | Normal because it effects just one piece of functionality: language orders. (not a whole system). |
Unfrozen changes | Not unfrozen. |
Disruption | Not disruptive for core/contributed and custom modules/themes because it will not require a BC break/deprecation/internal refactoring/widespread changes. |
Proposed resolution
Give a newly added language a weight. Set it higher than the previously added configured language. (Locked languages keep getting weights bigger than this newly added one based on pre-existing code). Add tests.
Remaining tasks
User interface changes
Languages have an expected order out of the box in the order they are added.
API changes
None.
Comment | File | Size | Author |
---|---|---|---|
#49 | interdiff.txt | 807 bytes | catch |
#46 | interdiff.txt | 938 bytes | Gábor Hojtsy |
#46 | 2350933.46.patch | 6.43 KB | Gábor Hojtsy |
#42 | 2350933-2.42.patch | 6.39 KB | alexpott |
#42 | 39-42-interdiff.txt | 7.42 KB | alexpott |
Comments
Comment #1
Gábor HojtsyComment #2
YesCT CreditAttribution: YesCT commenteddid beta evaluation according to https://www.drupal.org/contributor-tasks/update-allowed-beta
disruption guess might need to be updated, but for now, this looks to be allowed in the beta.
Comment #3
YesCT CreditAttribution: YesCT commentedComment #4
rodrigoaguileraI'll work on this one
Comment #5
rodrigoaguileraHere's a patch that adds +1 to the newly added language leaving the default weight when we have the first language addded.
I'm not very sure if that is a very proper way to test.
I think is an overkill to test changing the language of the interface to check if the weight order is respected.
Comment #7
rodrigoaguileraAdded a check to ConfigurableLanguageManager so it doesn't try to update the weight on a non-configured-yet language.
Comment #8
rodrigoaguileraWrong patch
Comment #11
rodrigoaguileraMore test corrections that took assumptions about how languages were ordered
Comment #12
rodrigoaguileraRemoved debug call in the test
Comment #13
rodrigoaguileraComment #14
YesCT CreditAttribution: YesCT commentedThanks for working on this issue.
Cool. it is green. :)
To make it more likely that you will get reviews, please make interdiffs when posting a new patch on an issue that already has a patch.
For instructions on creating an interdiff, see https://drupal.org/documentation/git/interdiff
Also, Please make a "tests only patch" that does not have the +1 fix, and just has the changes to the test.
That tests only patch will fail (hopefully). And then we can verify that it fails in the correct way. And we will know that this bug will not return in the future.
The contributor task doc on how to write tests at https://drupal.org/contributor-tasks/write-tests has some more info on test only patches.
Comment #15
YesCT CreditAttribution: YesCT commentedthere are some fixes to clean up standards in here that are in some of the files being touched, but in lines not being changed for this issue.
So, to make this reviewable, we should only make the changes we need to (or fix standards things in lines we have to change to fix the issue)
Seems like the test coverage here might be good enough, so removing the needs tests tag.
Comment #16
rodrigoaguileraComment #17
rodrigoaguileraRemoved the coding standards fixes.
interdiff between #12 and #17
and a test only patch
Comment #18
rodrigoaguileraComment #20
rodrigoaguileraComment #21
Gábor HojtsyHuge thanks for working on this, this looks generally good, two notes:
Under what conditions would a locked language not be present?
I think it would be important to make the distinction that you only take configurable languages here.
Comment #22
rodrigoaguileraAbout 1.
I did that because of tests failing during the install of locale and language modules at patch in #5
https://qa.drupal.org/pifr/test/951998
For example CKEditorTest.
I'm wild guessing here but maybe the locked languages are not configurable yet until language module is fully installed and configurableLanguageManager trying to change the weights.
About 2.
I'll change it for
$this->getLanguages($this::STATE_CONFIGURABLE);
Comment #23
Gábor Hojtsy@rodrigoaguilera: 1. aham, makes sense. 2. I think making sure the comments mention that too would be good.
Comment #24
rodrigoaguilerafirst the rerrol
Comment #25
rodrigoaguileraAnd the changes
Comment #26
rodrigoaguileraComment #27
Gábor HojtsyLooks good to me :) Thanks! Also updated issue summary.
Comment #28
Gábor HojtsyRetitled once more as appropriate for a bug.
Comment #29
Gábor HojtsyComment #30
alexpottWhy is this change necessary?
Comment #31
Gábor Hojtsy@alexpott: I had the same question above in #21 and got answered in #22. In short it is for the brief transitional period when ConfigurableLanguageManager is already loaded but the configuration is not yet imported for those languages.
Comment #32
alexpottLet's only do this when
$this->isNew()
is TRUE and the weight is not zero.Comment #33
alexpottThe changes in #25 overwrote any weight value already set. Also the question in #30 can be answered differently. If you are doing a kernel test base and the enabling language then you have to install its configuration because the configurable language manager relies upon.
Comment #34
Gábor HojtsyThanks @alexpott for the fixes, makes sense to me. Also fixing a case problem in method invocation and I think this should be good :)
Comment #35
catchJust comment nits..
Why exclude English from here? Could use a comment.
What is French?
Comment #36
alexpottRerolled and improved code comments as per #35.
Comment #37
Gábor HojtsyThe updated sentence does not make sense. One "and" too much?
Comment #38
alexpottBased on catch's questioning and writing tests I think we need a new approach. This makes the default value NULL and if it is NULL make it the last weight +1. If we want to ensure that ConfigurableLanguages have unique weights then we have to go way further.
Comment #39
alexpottOops.
Comment #41
Gábor HojtsySounds like a good approach to differentiate explicit and implicit weights.
When we mention languages in comments and tests, we still uppercase them. You mostly uppercase them, these are exceptions and therefore inconsistent.
Comment #42
alexpottAnother approach :)
Also looking at
I think sorting on something that is translatable might be problematic here.
Comment #43
Gábor HojtsyMost things that people would sort by traditionally are translatable, especially titles. Even creation dates and last updated dates on content entities :)
Comment #44
Gábor Hojtsy@alexpott: looking at the newest approach patch, why would we not do the weight adjustment on creating a new language with the API? The latest patch only deals with creation on the UI.
Comment #45
alexpott@Gábor Hojtsy with the API you are free to do what you like. Also there is no API for saving multiple languages at once.
Comment #46
Gábor HojtsyOk, I agree that to resolve the UX problem, solving it in the form is fine too. Attached is a minor doc fix. I think this is RTBC.
Comment #47
webchickCommitted and pushed to 8.0.x. Thanks!
Comment #49
catchOne minor docs typo fixed on commit.
Committed/pushed to 8.0.x, thanks!
Comment #50
Gábor HojtsyThanks!