Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
There is no need to use t()
in tests, unless we're testing translations, however in core we do not follow this consistently, which does not set a good example for new contributions.
In #3133726: [meta] Remove usage of t() in tests not testing translation we identified there are over 2,200 calls to t()
in calls to drupalPostForm()
and that removing all these in one go seems to be a suitable way of attacking this problem.
Proposed resolution
Identify and remove all calls to t()
wrapped in calls to drupalPostForm()
, except those used by translation-related code (if any).
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#49 | interdiff_44-49.txt | 7.31 KB | mondrake |
#49 | 3145005-49-91x.patch | 1.11 MB | mondrake |
#48 | interdiff_44-48.txt | 7.29 KB | mondrake |
#48 | 3145005-48-92x.patch | 1.11 MB | mondrake |
#44 | 3145005-44-9.1.x.patch | 1.11 MB | longwave |
Comments
Comment #2
longwaveUsed this script to generate the first patch:
Let's see what testbot comes back with. There are a few more manual fixes that can be made on top of this, but it looks like a good start.
Comment #3
longwaveSlightly surprised that that passed with no errors!
Manual fixes done, I can't find any more calls to t() inside drupalPostForm().
Comment #5
cburschkaSmall string concatenation issue.
Comment #6
dwwThanks for this! Seems like a great start. Very cursory scan looks really good.
Bot found some CS bugs:
Thanks,
-Derek
Comment #7
cburschkaComment #8
longwave@cburschka Thanks for fixing up my mistakes :)
I cannot RTBC as I wrote the initial patches but I don't have anything else to add, this looks good to me.
Comment #9
dwwBefore:
After:
The 4 are false hits from being too permissive with searching for: "t("
Tests all pass. Bot's happy with code style.
I can't handle line-by-line reviewing a 1mb patch of nearly 20K lines. :/ But a spot check looks totally reasonable everywhere I inspected. I can't imagine @longwave nor @cburschka are trying to sneak in anything here. ;)
Comment #10
longwaveAnyone who wants to double check the patch integrity can run the shell command in #2 and then apply the following three interdiffs. Then you only have to trust the shell command itself and the interdiffs are reviewable :)
Also note that we might have to recreate this patch for other branches using a similar process, if it is to be backported to make cherry-picking other patches easier.
Comment #11
mondrakeComment #12
Lal_re-roll of #7 as it failed to apply
Comment #13
Lal_Comment #14
naresh_bavaskar@lal_ I tried to apply the patch, but getting an error (attached screenshot)
also, it will be good if you provide interdiff as well here
Comment #15
nitesh624Comment #16
cburschkaMerged 9.1.x.
@naresh_bavaskar, attaching screenshots of your CLI does not really help
Comment #17
longwaveI diffed #7 and #16 and only changes are rerolled lines, so back to RTBC.
Comment #18
dwwRemoving credit and screenshot from #14 that was embedded in the summary.
Comment #19
xjmThanks for working on this monster!
Unfortunately, this already does not apply. Typically, with cleanups this large, we schedule them during the beta or RC phase of a release, to avoid disrupting ongoing work.
The beta window for 9.1 is the week of November 2, so we'd want to schedule it for sometime the week of November 9 or following.
Is someone able to regenerate that patch then? I know it's a ways out.
Comment #20
longwaveUnderstood. I will put this in my calendar and try to get to it in November!
Comment #21
mondrakeComment #23
PasqualleComment #24
longwaveRerolled.
Comment #25
mondrakeWonder if it would make sense to try, in a test issue, to add a temp deprecation trigger like we did in other issues of this kind, to check if any leftover calls remain with an object passed in.
Regardless, this is good cleanup.
Comment #26
longwaveRe #25 I added a deprecation warning in #3180410: longwave patch testing
Comment #27
longwaveNeeds work for the fails in https://www.drupal.org/pift-ci-job/1871376
TBH maybe we should just add the deprecation here, we already have two in this method, adding a third will help everyone migrate away from drupalPostForm more cleanly.
Comment #28
mondrake#27 +1 yes, in this case it would be probably better to explicitly cast
$subject
to string in the likely rare case it happens to be an object.Comment #29
longwaveAdded a deprecation warning and fixed all remaining cases that were triggered by said warning.
None of the cases need casting - we can always pass plain strings.
Comment #31
mondrakeCouple more changes.
Comment #32
mondrakeWe need a deprecation test for the @trigger_error added in #29.
Comment #33
raman.b CreditAttribution: raman.b at OpenSense Labs commentedAddressing #32
Comment #35
raman.b CreditAttribution: raman.b at OpenSense Labs commentedComment #36
longwave#31 covers the two things I missed and great work in #33, that's a nice clean way of adding an extra test here!
Comment #37
mondrakeThere's a code standard failure now,
core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php ✗ 1 more
line 863 Do not pass empty strings to t()
Comment #38
longwaveComment #39
mondrakeAssuming it turns out green.
Comment #40
mondrakeComment #41
longwaveRerolled.
Comment #42
catchPatch no longer applies. We also need a 9.1.x patch without the deprecation or test for it (i.e. just the t() removal).
Comment #43
longwaveComment #44
longwaveLots of conflicts, so I reused the script in #2 to automatically fix up the rejected hunks. This may have missed some, let's see...
Comment #47
mondrakeFixing the issues.
Comment #48
mondrakeThe 9.2.x patch, 9.1.x one next
Comment #49
mondrake9.1.x patch, without deprecation and test
Comment #51
mondrake#50 was a random failure.
Back to RTBC since I basically just rerolled.
Comment #52
catchCommitted/pushed to 9.2.x and 9.1.x, thanks!
Comment #53
longwaveDoesn't look like this was pushed to git?
Comment #56
longwaveAh, there it goes!