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.
In #2221771: Mark all simple wrappers in bootstrap.inc and common.inc as deprecated the function format_string()
is deprecated. Let's remove all calls to it.
Comment | File | Size | Author |
---|---|---|---|
#116 | 2228741-116.patch | 441.78 KB | voleger |
#115 | interdiff-2228741-90-115.txt | 2.1 KB | voleger |
#115 | 2228741-115.patch | 441.7 KB | voleger |
#115 | 2228741-115-just-reroll.patch | 441.14 KB | voleger |
Comments
Comment #1
Rolf van de Krol CreditAttribution: Rolf van de Krol commentedComment #2
Rolf van de Krol CreditAttribution: Rolf van de Krol commentedAll invocations of the above mentions functions are removed and replaced with calls to String::xxx.
Comment #4
Rolf van de Krol CreditAttribution: Rolf van de Krol commentedComment #6
ianthomas_ukI've changed this to just format_string(), since the others have either been done already or are trivial so can be done in the deprecation patch.
Comment #7
malotor CreditAttribution: malotor commentedComment #8
malotor CreditAttribution: malotor commentedI have replace format_string with String:format in core
Comment #9
malotor CreditAttribution: malotor commentedUpss i think i have replaced th delegated funcion format_string to. I will fix it
Comment #10
malotor CreditAttribution: malotor commentedComment #11
malotor CreditAttribution: malotor commentedI have added the "use" line to all files that need it.
Comment #12
rpayanmComment #15
ianthomas_ukGiven the number of things that need changing here, I strongly suggest using #2208607: Write script to automate replacement of deprecated functions where possible
Comment #16
malotor CreditAttribution: malotor commentedMaybe it is the correct way
Comment #17
malotor CreditAttribution: malotor commentedThe fails seems easy to solve. I´ll try.
Fatal error: Cannot use Drupal\Component\Utility\String as String because the name is already in use in ./core/modules/simpletest/src/KernelTestBase.php on line 22
Errors parsing ./core/modules/simpletest/src/KernelTestBase.php].
[07:21:35] Encountered error on [syntax], details:
Comment #18
malotor CreditAttribution: malotor commentedError fixed
Comment #19
rpayanm@malotor you must change the status to "Needs review" for test the patch.
Comment #21
malotor CreditAttribution: malotor commentedok rpayanm , thanks.
Comment #22
malotor CreditAttribution: malotor commentedComment #23
malotor CreditAttribution: malotor commentedTonight, I will try to install in order to find this install failure
Comment #24
malotor CreditAttribution: malotor commentedComment #25
rpayanmComment #26
malotor CreditAttribution: malotor commentedMaybe splitting the issue for each core module makes easy to create the a working patch-
Comment #27
ianthomas_ukThe patch should be easy to make if you use the script from #2208607: Write script to automate replacement of deprecated functions where possible
When a patch fails testing the testbot will set the issue to needs work - there's no point setting it back to needs review at that point because the testbot has already found a problem with the issue. There are links below the dropdowns if you don't understand what they mean.
Comment #28
rpayanmLet me try :)
Comment #29
rpayanmups... hidden the files again...
Comment #31
rpayanmAgain...
Comment #32
quietone CreditAttribution: quietone commentedPatch in 31 didn't apply, so a reroll. It was a bit tedious (maybe working too late).
The conflicts were in these files:
core/modules/text/src/Tests/TextFieldTest.php
core/modules/system/src/Tests/Common/SystemListingTest.php
core/modules/field_ui/src/Tests/ManageFieldsTest.php
core/modules/entity_reference/src/Tests/EntityReferenceFormatterTest.php
Comment #34
quietone CreditAttribution: quietone commentedNot bad, only one small error.
Comment #35
quietone CreditAttribution: quietone commentedComment #36
ianthomas_ukA patch of this size would presumably be considered disruptive according to https://www.drupal.org/core/beta-changes, and therefore not committed at this time. Our time would be better used on the other issues on the meta (particularly those needing review), then we can come back to this when there are fewer critical patches to disrupt.
(see also #2350615-49: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase? to comment #52)
Comment #37
ianthomas_ukAlso postponed on #2454447: Split Utility\String class to support PHP 7 (String is a reserved word)
Comment #38
andypostComment #39
andypostComment #40
rpayanmAnd the call
String::format
would by converted toSafeMarkup::format()
?Comment #41
andypost@rpayanm yes, that need discussion how to split the units to cover all #2454439-14: [META] Support PHP 7
Comment #42
rpayanmComment #43
rpayanmRound 1.
Comment #45
rpayanmOf course.
Round 2.
Comment #47
rpayanmNice.
Round 3.
Comment #49
rpayanmYes, yes, yes :)
Round 4.
Comment #51
rpayanmLet me see.
Round 5.
Comment #53
rpayanmAnd again.
Round 6.
Comment #54
dawehner@rpayanm
Have a look at my previous patch: https://www.drupal.org/files/issues/2454447-23.patch and search for
'\Drupal\Compo
This will let you find a couple of more instances.
Comment #56
rpayanmthis should be green.
Comment #57
rpayanm@dawehner this issue id for format_string, if I search for
\Drupal\Compo
I got, for example:And not objective of this issue.
I search on PHPStorm for format_string and String::format and not found any occurrence, only the function.
Comment #58
Mile23Comment #59
siva_epari CreditAttribution: siva_epari commentedPatch rerolled.
Comment #60
Mile23Sorry... :-)
You can probably blame #2401191: Activity Tracker shows 'Last updated' status as '45 years 1 week ago'
Comment #61
siva_epari CreditAttribution: siva_epari commentedNo need to blame :-) I am happy to contribute. Patch rerolled.
Patch size reduced. Thanks to #2457887: Use Utility\SafeMarkup class instead of Utility\String for placeholder(), checkPlain(),format() functions
Comment #63
siva_epari CreditAttribution: siva_epari commentedUploaded the patch in haste. Fixed all unmerged issues & duplicate errors.
Comment #65
siva_epari CreditAttribution: siva_epari commentedRemoved more duplicates of "use Drupal\Component\Utility\SafeMarkup;" which crept in during reroll.
Comment #66
Mile23Looks good, thanks for sticking with it.
After applying the patch, NetBeans can't find any occurrence of
format_string()
, other than the function definition which still remains. Probably need a follow-up issue to remove it.Comment #67
xjmThanks everyone for your work on this! Unfortunately, this patch can no longer go in during the beta phase of the Drupal 8 release cycle:
Following the flowchart in the Allowed beta changes:
format_string()
is just a wrapper anyway).Whenever an issue is a normal task, be sure to evaluate right away if it can be accepted during the beta. We can clean up these uses of deprecated code again before 8.1.x.
Comment #68
siva_epari CreditAttribution: siva_epari commentedxjm, thanks for the evaluation. I agree with it!
Comment #69
TR CreditAttribution: TR commented@xjm: Would you accept a patch for 8.0.x that just affected the tests and didn't touch the rest of core?
Comment #70
dawehnerWe have 5 of them left, IMHO this should not be 8.1 material
Comment #71
TR CreditAttribution: TR commentedNow that #2221771: Mark all simple wrappers in bootstrap.inc and common.inc as deprecated has gone in and format_string() is deprecated, I think it's important to re-open this issue and get this finished.
I think any disruption to current core issues would be a good thing - we don't want to be committing *more* code with the deprecated format_string() function. format_string() was obsoleted more than a year ago - we really *should* be breaking any pending patches that still use format_string().
Agreed this is not a priority, but as core serves as an example (and sometimes the only available documentation) for what can be done in contrib, it makes sense to get core usage of format_string() removed BEFORE 8.0 is released, otherwise all of contrib is going to start copying core and it will become far *more* disruptive to try to change this. At the very least, removing format_string() from tests is within the allowed beta changes, and this accounts for most of the core usage.
@dawehner: What do you mean by 5? I count ~750 instances of format_string() in core ...
Comment #72
xjmAgain, it's deprecated for 9.0.0 at present, which means we are committed to keeping it in core for the full 8.x.x cycle. Unless we also end up removing
SafeMarkup::format()
as part of #2549943: [plan] Remove as much of the SafeMarkup class's methods as possible (which I think would be too disruptive and @alexpott said probably was not on the table as of at least last week), we don't gain much by converting core usages.Not re-postponing yet though; I'll ping alexpott asking for a second opinion. But by itself; this is not eligible as a change during the beta (see #67); the only reason to consider it would be as part of #2549943: [plan] Remove as much of the SafeMarkup class's methods as possible.
Comment #74
Mile23Such a huge patch and so much effort, and now SafeMarkup is deprecated in favor of FormattableMarkup. :-)
Some of the changes are more narrowly addressed in #2549805: Remove all usage of FormattableMarkup in tests apart from explicit tests of that API
Comment #75
Mile23Woops. Meant to add that as related.
Comment #80
alexpottComment #81
andypostgrep returns 724 places which is too much for single patch to review properly
Better to create a meta(plan) issue to split this conversion into subtasks like #2549805: Remove all usage of FormattableMarkup in tests apart from explicit tests of that API
Comment #82
alexpott@andypost I disagree. This can and should be scripted.
Comment #83
andypost@alexpott scripting will require to be smart to modify
use
(kinda usecase for pharborist or ast) but idea is interestingAlso it should exclude tests that in progress of conversion in #2549805: Remove all usage of FormattableMarkup in tests apart from explicit tests of that API
Comment #84
alexpott@andypost I'd go the other way around here. And fix this before #2549805: Remove all usage of FormattableMarkup in tests apart from explicit tests of that API - I'd also fix #2958429: Properly deprecate SafeMarkup::format() first and then the test issue only has to deal with FormattableMarkup.
Comment #87
mikelutzComment #88
mikelutzComment #89
mikelutzComment #90
mikelutzHere's a fresh patch against 8.8. General regex and replace, plus a script to add in the use statements. Added a test.
Comment #91
mikelutzComment #92
mikelutzI used the below to fix the use statements after the global S&R. It took care of all but about a dozen files which I updated manually.
Comment #93
mikelutzComment #94
mikelutzReroll
Comment #95
mikelutzMy only other question for this is do we want to remove some of the redundant usages of markup in test messages as part of this patch, or is that relegated to one of the followups, which will remove new FormattableMarkup now instead of format_string?
Comment #96
mikelutzComment #97
mikelutzReroll
Comment #98
mikelutzCurious what a bulk S&R removing Formattable markup messages from any ->assertEqual/assertEquals calls looks like
Comment #100
mikelutzFix tests, remove some extra hunks.
Comment #101
mikelutzComment #102
mikelutzAlso, you know, the patch file, just for fun...
Comment #103
mikelutzRerolling
Comment #104
LendudeAs discussed on slack, this is not in alphabetical order, but that is not a hard standard, so this will do, since a fair number are not in alphabetical order to begin with (possibly from other scripts). So no action needed here.
as discussed on slack, lets stick with assertEqual so we don't have to flip arguments.
Went through most of the patch (10% in detail, lots in scan mode), and these were the only issues that I saw. The added test coverage looks good.
Comment #105
mikelutzscripted restoration of the assertEqual
Comment #107
mikelutzFixed remaining test (just missing use statements) . Then manually wen through each test file, and cleared out additional unneeded usages in test messages.
Comment #108
mikelutzFixing a couple typos
Comment #110
BerdirAs mentioned on slack, sorry for this being so huge, but I'm prepared to RTBC after this is addressed.
This is not a format_string(), so not really in context, maybe was a merge conflict or so. Also IMHO useful information.
This seems useful too, as it is in a loop and you otherwise don't know which property that didn't match.
I also suggested to exclude all tests in src/Tests because those are legacy simpletest tests that we'll remove anyway and it helps to make the patch a bit smaller.
these are the non-deprecated versions of the above.
the first seems useful too as this is inside a loop that is testing multiple ones, so not obvious to see which one failed. The second one has an argument too but that's actually hardcoded above and only one is tested in that method, so seems fine to remove.
same here, on the first it's the delta, those below have a loop over revisions and deltas.
another one of these.
those two and other similar token tests loop over pretty long lists of tokens, so knowing which token actually failed is important.
not sure about this. it's a helper function, but it's relatively easy to see from backtrace which call that failed. If we do remove it then you can also remove $t_args which is now unused.
these two have the filter name in a loop, might be useful?
also tricky, this seems like useful information at first, but the image style is a random string and there's only one it seems. But $image_path seems unused now, so we could remove that (a few times)
hm, in this file you keep it on assertFieldByXpath() but remove it from assertEqual() but those are basically doing kind of the same, so we should either remove both or keep both (keeping seems easier to review, involves less thinking :))
if we remove it then we can remove NULL to, that was just here so we could have a message. $type is part of the field name, so safe to remove I'd say.
useful?
hm, we could make these two assertEquals(), then we get useful default output.
phpunit has assertCount, we could use that and drop the messages?
useful?
useful
that %numer/i/type thing might be useful?
could use assertNotInstanceOf() and then drop the message?
another one of those token tests, useful.
deprecated legacy base test class, skip :)
same.
pager number useful?
field/sort order useful?
handler name is kinda useful. also, not using it means the method argument $handler_name would now be unused and cleaning that up would be much more work :)
these are all in loops, so useful? also you still have the switch to assertSame() here but didn't switch the argument order.
more loops that are useful?
identical -> same, but here the expected is first already, so might be ok. $type might be useful, maybe remove the expected/returned part?
these could use assertArrayNotHasKey then we could drop the messages, but I'm not sure how far we want to go with these changes :-/
this compares with a boolean, so is technically an asertTrue/False. module is useful information (and message would be unused now.)
identical/same change.
more things that could use assertArray(NOt)HasKey and assert(Not)Contains if we'd want to, but as mentioned before, likely too much for this issue.
remove is fine, but identical/same with wrong order.
more
assertPattern() doesn't have a message argument
hm, $condition specifically exists to be shown in the message, seems useful and if we remove it you need to clean up the argument and calls to it ;)
$key useful?
token test, useful.
more token tests.
$oformatter useful?
identical/same switch.
this line is useless with phpunit, it only exists to show debug info in the output table in simpletest but phpunit doesn't show passed assertions. and if one fails then we have it below.
follow-up to deprecate these in favor of assertContains()?
$entity might be useful?
@token seems useful, we could drop $ouptut but that will only make the patch bigger..
identical/same, although order is correct here. you might want to search if I found all of them ;)
removel is fine I think, aggregation function is obvious from the name of test method calling this helper.that information was not available in simpletest, but is in phpunit.
more token stuff.
identical/same
same and property seems useful.
same and same (property)
another useful property
identical/same
these passes are also pretty useless (all calls to pass() are I guess). not sure if you want to remove them here or not.
task useful?
this seems useful as it is a loop and you need to know which operation failed. it's an assertEqual() but again really a boolean comparison.
those two checks do exactly the same, a bit arbitrary to remove one message and keep the other because assertEqual()/assertTrue. I'd either remove both or keep both.
the thing with all these assertions is that the whole method runs with different entity types, so we lose the info on which one it fails with all those removals. not just this assert or even this method but several huge chunks around here.
identical/same
Comment #111
LendudeThe removing/changing of messages seems to introduce a lot of extra scope to this, that, I think, is really not needed. Shouldn't we just do a 1-1 conversion here and worry about the messages later? We need to do that any way since this only addresses the part of the messages that happen to use format_string(), there are a lot of other messages that need removing/updating.
Comment #112
Gábor HojtsyRaised this with core committers as well. @alexpott wrote this and then @larowlan chimed in to agree:
It is WAY easier to review a 400k patch when there are no changes to debate one by one, I agree. So let's focus only on replacing the use of deprecated API and making our tests better separately.
So back to around the state at #90 for a much faster commit :)
Comment #113
volegerJust reroll of #108
Comment #114
volegerFix CS issues.
Comment #115
volegerPlease ignore #113 and #114 comments.
Just reroll patch based on the #90. Addressed #112.
Also, the patch which fixes CS issues in deprecation messages.
Comment #116
volegerReroll
Conflict was in
core/modules/filter/tests/filter_test/src/Plugin/Filter/FilterTestPlaceholders.php
Patch is ready for the review
Comment #117
catchLet's open a follow-up for the changes in #108. Agreed with doing a direct find and replace here just to sort out the deprecation.
Comment #118
voleger#3066933: Cleanup formatted messages in the tests filled. Feel free to update IS of the issue in case if there are not fully highlighted the scope of the issue.
Comment #119
LendudeScanned through the changes and the important bits are there:
So I guess the green tests means we got everything.
Only thing I see remaining is the mention of format_string in
\Drupal\Tests\Core\Logger\LogMessageParserTest::providerTestParseMessagePlaceholders
which we might want to clean up, but I would propose doing that in a follow up too, just to keep the scope here as small as possible.RTBC I would say.
Comment #120
alexpottCredited @Mile23, @andypost, @ianthomas_uk, @alexpott, @dawehner, @xjm, @Gábor Hojtsy, @Berdir, @Lendude and @catch for general issue management, review, and online discussion.
Committed e39262b and pushed to 8.8.x. Thanks!