Problem/Motivation
The order of the projects from locale_translation_get_projects() is not consistent. If the project list is rebuilt it will be in the order returned from locale_translation_project_list(). This might be altered to ensure a particular translation project is last. However, once the cache has been built the order of the projects is in whatever order \Drupal::service('locale.project')->getAll() returns them from the database.
The order needs to be consistent and never change if the underlying code does not change i.e. module weights / alters etc.
Steps to reproduce
Proposed resolution
Order by key alphabetically, as this is the current behaviour once the projects have been stored in the storage, but allow alters to set a wright key that can change the order to ensure translations come before or after each other as desired.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
New optional weight key in project information.
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | 3403337-nr-bot.txt | 1.74 KB | needs-review-queue-bot |
Issue fork drupal-3403337
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
alexpottComment #4
gábor hojtsyI think this makes sense. Why do you need to add the NULL filter though? How is that related?
Comment #5
alexpottComment #6
alexpott@Gábor Hojtsy because LocaleProjectStorage is has several bugs - if you don't add the NULL filter than the key will remain in the ouput if you do ::getAll after a ::delete... the new test added here confirms tests this behaviour and leaving the bug in felt irresponsible.
Also fixed here is changing the property all from a static to a regular class property because that has no business being static when $cache is not.
Comment #7
alexpottThe one thought here is should we obey the order generated by
locale_translation_project_list()instead or adding a weight key and sorting by key.The sorting by key behaviour is the current behaviour - unless you've just called
locale_translation_build_projects()for the first time. At that point it will be in the order thatlocale_translation_project_list()returns until the process ends. Any subsequent process will get it in the key order.I went for the current change because I think it is less risky for current sites which might be relying on the current order to have translations work out the way they want.
Comment #8
penyaskitoCode-wise LGTM.
The only issue we can have with this is altering what people is expecting on their projects. But given we are actually making it deterministic, any expectation they had before this MR is merged is actually wrong and not reliable. So it's definitely not making things worse for them, actually providing a way to fix it via weight if they need to.
So IMHO this is RTBC.
Comment #9
alexpottCreated the CR - https://www.drupal.org/node/3404117
Comment #11
quietone commentedI'm triaging RTBC issues. I read the IS and the comments. I didn't find any unanswered questions.
I read the MR and found a grammar error which I fixed, and I also rebased. The change record also had a sentence that needed rewording so I did that too. I also moved the example to a separate heading.
I tested locally and the test does fail without the code changes.
I also updated credit.
Since the change to the MR was minor in a comment I am leaving at RTBC.
Comment #12
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #15
akhil babuAdded
declare(strict_types=1)to the test as per #12. Moving to needs reviewComment #16
smustgrave commentedLeft some small updates. Leaving in NR for additional eyes.
Comment #17
smustgrave commentedFeedback has been addressed
Comment #18
quietone commentedI'm triaging RTBC issues. I read the IS, the comments and the MR.
I left some work in the MR, so setting to needs work. I just noticed that I suggested a change that alexpott removed but I have to go right now and can't follow up.
Comment #20
vakulrai commentedUpdated the comments in the MR , please review !
Comment #21
alexpott@vakulrai
return array_filter($this->cache, fn ($value) => $value !== NULL);is not the same as
return array_filter($this->cache);The latter will remove empty arrays, FALSEs and empty strings which is not the current behaviour. We only want to remove the NULLs and the \Drupal\Tests\locale\Kernel\LocaleTranslationProjectsTest::testLocaleTranslationClearCacheProjects() relied on this.
Comment #22
quietone commentedSo, I made comments on the MR but didn't save them. I have done that now but now the conversation isn't in the correct order.
Comment #23
quietone commentedThe result of the last day here is changes to comments. And I just made another one to correct tense. The questions I raised in the MR resulted in code changes that were reverted by alexpott, with explanation.
Comment #24
smustgrave commentedReviewed and appears that feedback has been addressed
Comment #27
catchReviewing this I had a similar thought process to #7 and would have leaned on respecting the order of local_translation_project_list() but I think that would have taken even more refactoring, so adding the explicit weight key seems OK.
Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!
Comment #30
longwaveReverted, as the new unit test fails on PHP 8.3 (but not 8.1 or 8.2):
Comment #31
alexpottTurns out this is a PHP 8.3 bug - see https://github.com/php/php-src/pull/13285 - fortunately a work around is pretty simple - see https://git.drupalcode.org/project/drupal/-/merge_requests/5507/diffs?co...
Comment #32
alexpottAlso in the interim testing is now defaulting to PHP 8.3 so if we the main pipeline is green we know we're fixed it.
Comment #35
longwaveNice that we found a PHP bug, even better that it's already fixed - and that we can work around it here.
Committed and pushed e7e4e0e776 to 11.x and c1634b16eb to 10.3.x. Thanks!