Instructions
This is part of #2093143: [meta] Remove calls to @deprecated and "backwards compatibility" procedural functions from core
Writing patches
We want to replace calls to check_plain(), and any references in the documentation, to Drupal\Component\Utility\String::checkPlain()
To do this, we don't want to have to write the whole "Drupal\Component\Utility\String::checkPlain()" every time so we want to use namespace aliases so that we can simply write String::checkPlain() - see the PHP documentation http://www.php.net/manual/en/language.namespaces.importing.php
We need to be sure that each file that needs to use String::checkPlain()
has the statement use Drupal\Component\Utility\String;
at the top of it.
Automatic patching
Instead of doing taking the manual approach I decided to create a tool d8codetools .
~/dev/drupal $ ~/d8codetools/function_replace.php 'check_plain' 'Drupal\Component\Utility\String' 'UtilityString' 'checkPlain'
Converting existing patches
IMPORTANT: Most of the work for this issue has already been done in #2089465: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/A-L and #2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest) but because the patches touched basically all of core they needed to keep being re-written. For that reason we are splitting those issues into per-module issues but the code changes in the patches from the large issues should be re-cycled as much as possible.
Issues
Needs work:
Postponed on "Disruptive Day":
- #2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest)
- #2196817: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in comment module
- #2196835: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in entity_reference module
- #2196839: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in field/field_ui module
- #2196841: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in file module
- #2196893: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in filter module
Done!
- #2187829: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/views
- #2093167: Deprecate check_plain(), call \Drupal\Component\Utility\String::checkPlain() directly instead
- #2089461: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/lib
- #2089465: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/A-L Assigned to: thedavidmeister
- #2196797: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in action module
- #2196801: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in aggregator module
- #2196805: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in ban module
- #2196807: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in block module
- #2196811: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in book module
- #2196815: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in color module
- #2196895: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in forum module
- #2196897: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in image module
- #2196901: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in language module
- #2196907: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in link module
- #2196909: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in node module
- #2196951: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in picture module
- #2196995: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in rest module
- #2196821: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in contact module
- #2196825: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in content_translation module
- #2196831: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in edit module
Comment | File | Size | Author |
---|---|---|---|
#99 | 2089331-99-checkplain.patch | 99.91 KB | grom358 |
Comments
Comment #1
thedavidmeister CreditAttribution: thedavidmeister commentedThere are a *lot* of calls to check_plain() so I thought I'd make this a meta and we can split out a bunch of novice conversions.
Comment #1.0
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #2
jibranIt is a novice task.
Comment #2.0
jibranUpdated issue summary.
Comment #2.1
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #2.2
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #2.3
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #3
thedavidmeister CreditAttribution: thedavidmeister commentedComment #3.0
thedavidmeister CreditAttribution: thedavidmeister commentedUpdated issue summary.
Comment #4
rpsu#2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest) needs non-novice review, see comment #15
Comment #5
netsensei CreditAttribution: netsensei commentedWe might need to split the module list into even smaller chunks or we'll risk chasing head forever. The two patches in the #2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest) and #2089465: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/A-L get outdated pretty fast.
Comment #6
thedavidmeister CreditAttribution: thedavidmeister commented#5 - I'd be happy for that to happen, but whoever splits one issue into multiple should also be the same person to split the existing patches appropriately. Let's not throw out work that's already been done.
Comment #7
netsensei CreditAttribution: netsensei commentedYou're right. I'm also wary about splitting those up at this point. We should try and get both patches passed by the testbot first and see what happens next.
Comment #7.0
netsensei CreditAttribution: netsensei commentedUpdated issue summary.
Comment #8
sunComment #9
ianthomas_ukDo we intend to remove check_plain before Drupal 8.0? It's listed in https://docs.google.com/spreadsheet/ccc?key=0AusehVccVSq2dEttQ3k5WWNYVHB... as staying around until Drupal 9, but I don't think that's correct.
Comment #10
InternetDevels CreditAttribution: InternetDevels commented#2089465: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/A-L
#2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest)
Those two issues are too big to be done at once.
Seem that while patches will be created and reviewed they already will need a re-roll :)
For this moment I have created separated task for views/views_ui modules:
#2187829: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/views
Comment #11
thedavidmeister CreditAttribution: thedavidmeister commentedI'll start splitting this per-module.
Comment #12
thedavidmeister CreditAttribution: thedavidmeister commentedComment #13
thedavidmeister CreditAttribution: thedavidmeister commentedComment #14
thedavidmeister CreditAttribution: thedavidmeister commentedComment #15
thedavidmeister CreditAttribution: thedavidmeister commentedComment #16
thedavidmeister CreditAttribution: thedavidmeister commentedComment #17
thedavidmeister CreditAttribution: thedavidmeister commentedComment #18
thedavidmeister CreditAttribution: thedavidmeister commentedComment #19
thedavidmeister CreditAttribution: thedavidmeister commentedComment #20
thedavidmeister CreditAttribution: thedavidmeister commentedComment #21
thedavidmeister CreditAttribution: thedavidmeister commentedComment #22
thedavidmeister CreditAttribution: thedavidmeister commentedComment #23
thedavidmeister CreditAttribution: thedavidmeister commentedComment #24
thedavidmeister CreditAttribution: thedavidmeister commentedComment #25
thedavidmeister CreditAttribution: thedavidmeister commentedComment #26
thedavidmeister CreditAttribution: thedavidmeister commentedComment #27
thedavidmeister CreditAttribution: thedavidmeister commentedComment #28
thedavidmeister CreditAttribution: thedavidmeister commentedComment #29
thedavidmeister CreditAttribution: thedavidmeister commentedComment #30
thedavidmeister CreditAttribution: thedavidmeister commentedComment #31
thedavidmeister CreditAttribution: thedavidmeister commentedComment #32
thedavidmeister CreditAttribution: thedavidmeister commentedComment #33
ianthomas_ukSlow down a sec, do we really need separate issues for each module? Views was a special case because it had a big patch on it's own, but I thought we were looking at 50k patches each for A-L and N-Z? That's much more manageable than a load of 1k patches.
Comment #34
thedavidmeister CreditAttribution: thedavidmeister commentedComment #35
thedavidmeister CreditAttribution: thedavidmeister commentedComment #36
xjmYes, please do not create separate issues on a per-module basis here. This is problematic issue scoping. While there's some value in trying a small change for someone's first patch, on the whole, the added overhead isn't appropriate, especially if the same person rolls more than one of the patches.
We have a draft post that attempts to explain how to address issues like these:
https://docs.google.com/a/acquia.com/document/d/1zYDnu45djDBcU87sNgKk15C...
If someone is tackling these issues at DrupalSouth, I'd appreciate it if someone onsite there could get everyone working on those issues together and take a look at that document. :)
Also, these patches would be better targeted for the disruptive patch window.
Finally, I rescoped this meta. We should leave
check_plain()
in as a BC wrapper for the full 8.x release. (This was discussed recently on a call with all four core maintainers.)Comment #37
xjm@thedavidmeister, maybe you can help out here by getting these patches all rolled into one (up to a patch size of 50-100K), reviewing with
git diff --color-words
or finding reviewers, and getting a list of everyone who contributed to all the sub-issues for the commit message credit? Thanks!Edit: Also, see https://groups.drupal.org/node/394763 for more information on the post-alpha "disruptive patch window", which is when it's best to schedule scriptable patches like these with a core maintainer. That way, they can be rerolled and committed without having to chase HEAD forever.
Comment #38
sunIf that is really the case, then we can mark this issue won't fix (or move it to D9).
I vehemently disagree. There's no point in keeping @deprecated stuff around.
Comment #39
thedavidmeister CreditAttribution: thedavidmeister commentedLast time i checked with the core maintainers it was deprecated and so should not be called internally by core, but the check_plain() function itself could be left in place, or moved to a deprecated module #2042165: Add a 'deprecated' module that includes deprecated functions only when enabled.
I disagree with parts of the document, I can't comment on it, there's nothing open for discussion on d.o, it looks like the document is owned by a proprietary company... Is there somewhere this meta issue about scoping and what is "best for the community" can be discussed in an open way (not IRC please!).
Comment #40
xjm@thedavidmeister, apologies! I was just sharing the draft thoughts because we haven't made a post yet, and I want to make sure contributors don't sink time into rolling 900-byte patches that will be rejected. It was co-authored by @webchick and myself in response to a problem the core maintainers identified with a recent misunderstanding around meta issue management. I'll post a policy issue later and link here so we don't derail this issue.
Comment #41
xjm@sun, in most cases I agree, but for a handful of very common functions it makes sense to keep in valid, tested one-line wrappers. But let's discuss further on the @deprecated meta. :)
Comment #42
thedavidmeister CreditAttribution: thedavidmeister commented@xjm - that would be great. I would certainly love to discuss this meta meta issue somewhere public, even if it's clearly just a draft. I agree that this is not a good place to have this discussion, but it's relevant to the immediate task at hand so I'll leave my 2c and copy and paste to the policy issue when it becomes available :)
I personally believe that keeping "scriptable" issues as atomic as possible may increase effort from core maintainers but decreases effort overall from the community as it leads to re-rolls of smaller, easier to understand patches. Creating "disruptive patch windows" then causing many (likely more complex) patches elsewhere on d.o to need re-rolls is just moving the problem to somewhere less immediately visible.
More importantly, from my perspective, is that enforcing minimum sizes on patches is a policy that is exclusive to some people in some situations who want to contribute but may only have time/skills to post/review small, atomic patches. Maybe they're in a social situation like a casual core sprint and just want to get something up, maybe they're busy and only have 15-30 minutes before their train comes and want to smash something small, maybe they just feel like doing something really tiny because that's what they're in the mood to do - "first timers" aren't the only people who benefit from being exposed to quick and easy patches.
I would value inclusiveness, linearly scaling difficulty of metas, minimising disruptiveness of individual commits and accessibility over minimising administrative overhead (it's not like we couldn't find a new core maintainer who just focuses on "atomics" if we thought there was value in it).
I like the idea proposed by @xjm in #37 of keeping the issues and patches atomic, then someone who is helping manage the meta issue makes a "commit plan" with a core maintainer that merges multiple patches together into a single commit *at commit time* - that sounds like a smart, non-arbitrary (like "50k patch size") balance between competing needs - the size/composition of the patches can be determined on a case by case basis. Any patches that need re-roll at commit time can simply be excluded from the roll-up and re-scheduled when the conflict has been resolved. I'd be much happier to arrange something like that than multiple re-rolls of one big patch with an unknown commit horizon and low chance of avoiding merge conflicts that i know will likely disrupt the whole RTBC queue when it finally lands.
Comment #43
thedavidmeister CreditAttribution: thedavidmeister commentedComment #44
thedavidmeister CreditAttribution: thedavidmeister commentedComment #45
thedavidmeister CreditAttribution: thedavidmeister commentedComment #46
thedavidmeister CreditAttribution: thedavidmeister commentedComment #47
grom358 CreditAttribution: grom358 commentedHey I created a script to automate this and here is the patch
Comment #49
grom358 CreditAttribution: grom358 commentedMy bad with that patch. A duplicate use Drupal\Component\Utility\String
Comment #50
grom358 CreditAttribution: grom358 commentedAnother fix to the patch
Comment #51
grom358 CreditAttribution: grom358 commentedComment #53
grom358 CreditAttribution: grom358 commentedCause HEAD is still moving, I'm gonna improve on this script and submit it here, so the change can be made to core directly.
Comment #54
ianthomas_ukWe also need a commit message for this (#2089471: Convert all calls to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in core/modules/M-Z (except system/simpletest) probably has most people, but there might be some who've only worked on the little issues).
Comment #55
grom358 CreditAttribution: grom358 commentedWork in progress script that created this patch, https://gist.github.com/grom358/9106837
Comment #57
grom358 CreditAttribution: grom358 commentedManual fix to core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php since it had already imported a String class from different namespace
Comment #59
grom358 CreditAttribution: grom358 commentedYet another attempt at scripting the patch.
Comment #60
grom358 CreditAttribution: grom358 commentedAs I mentioned in previous comment I used a script to generate the patch, which is here https://gist.github.com/grom358/9106837
Its very much a prototype, but worked well enough to apply this check_plain change. I ran the command
~/dev/drupal $ ~/code_upgrade.php 'Drupal\Component\Utility\String' 'StringUtil' 'check_plain' 'checkPlain'
It will sort the use declarations inserting the use declaration given by the first argument. If there a conflicting use declaration it will use an alias (second arg). The third argument is the function call to replace and the fourth argument is the method name on the class for the new function call.
Comment #61
grom358 CreditAttribution: grom358 commentedComment #62
longwaveThe coding standards specify that UtilityString would be the correct alias here.
The reason this was split up in the first place is that chasing HEAD across a large number of files is too difficult; we are already repeatedly rerolling some of the smaller patches spawned from this issue.
Comment #63
grom358 CreditAttribution: grom358 commented@longwave this is why I decided todo an automatic solution. Can easily re-execute the script to change the alias.
Comment #64
thedavidmeister CreditAttribution: thedavidmeister commentedWe should run the script when a Core Maintainer is actually ready to commit, and we should leave out any patches that have conflicts in them when the script is run.
That way the patches being committed are minimally disruptive and we don't have to guess some "golden patch size" ahead of time.
Comment #65
thedavidmeister CreditAttribution: thedavidmeister commentednever mind my last comment, @catch has committed many of the smaller patches already :)
Comment #66
webchickI'm personally happy to set up a time to commit all of these as one big patch in order to minimize bloat to the RTBC queue and endless re-rolling work. The best time is generally right after an alpha release, where we set aside "disruption days" specifically for this purpose. I don't think we have an alpha scheduled for March yet, but it's generally roughly the middle of the month. Can we please postpone this effort until then, so the core committers can stay focused on beta blockers and other bug fixes?
Comment #67
thedavidmeister CreditAttribution: thedavidmeister commentedHere's an update on where we're at for this. Basically, someone (I'm happy to do this) has to look at the issues that were recently marked "CNW" by @webchick and see which ones can be postponed until disruptive patch day (because they're essentially RTBC) and which ones do need a bit more work before they could be committed.
Comment #68
thedavidmeister CreditAttribution: thedavidmeister commentedComment #69
thedavidmeister CreditAttribution: thedavidmeister commentedComment #70
thedavidmeister CreditAttribution: thedavidmeister commentedComment #71
ianthomas_ukComment #72
thedavidmeister CreditAttribution: thedavidmeister commentedIncidentally, am I the only one who sees this issue has severe layout/css issues?
Comment #73
ianthomas_ukDo you mean the issue page, or are you reviewing the patch?
If you're talking about the issue page, that's something to possibly file a bug in the d7qa project, but it looks fine for me so you probably just need to do a shift-reload to re-fetch the broken CSS.
Comment #74
ianthomas_ukPostponing on #2208607: Write script to automate replacement of deprecated functions where possible
Comment #75
grom358 CreditAttribution: grom358 commentedhttps://drupal.org/comment/8582935#comment-8582935
Comment #76
grom358 CreditAttribution: grom358 commentedPatch created with function_replace.php at https://github.com/grom358/d8codetools
function_replace.php check_plain 'Drupal\Component\Utility\String' UtilityString checkPlain
Comment #77
ianthomas_ukComment #78
JiriK CreditAttribution: JiriK commentedPatch #76 applies cleanly, no check_plain() find when applied. Reviewed patch, it does not contain anything unexpected. No errors spotted after installation on screen or in log. Site seems to be working as before patching. Script used to generate the changes in the patch obviously works.
Comment #79
alexpottPlenty of check_plain still in the code base and not just comments :)
And needs a reroll.
Comment #80
grom358 CreditAttribution: grom358 commented@alexpott working on handling the array_map calls.. in regards to the comments.. what do we want todo there? Change it to \Drupal\Component\Utility\String::checkPlain()
Comment #81
grom358 CreditAttribution: grom358 commentedUpdated as per alexpott review
Comment #82
ianthomas_ukcheckPlain should be followed by brackets even in comments: checkPlain().
user.module has a few comments that are now over 80 characters.
core/modules/system/templates/links.html.twig still has a reference to check_plain()
Other than that I would RTBC this, but I noticed that it is going to conflict with #2089433: Remove uses of deprecated XSS filter functions which has some manual changes so is harder to reroll. Let's get that in, then come back and reroll this.
Comment #83
ianthomas_ukThis doesn't need to be postponed any more. @grom358 did you do any manual changes or is the command in #76 enough to reroll this?
Comment #84
grom358 CreditAttribution: grom358 commentedThe only manual changes I have been doing is wrapping the comments to 80 characters (but also have in pipeline to automate this).
Comment #85
grom358 CreditAttribution: grom358 commenteddelete me
Comment #86
grom358 CreditAttribution: grom358 commentedComment #87
grom358 CreditAttribution: grom358 commentedComment #88
grom358 CreditAttribution: grom358 commentedReroll PSR4
Comment #89
ianthomas_ukLooks good. All earlier comments addressed, applies without conflict and the only remaining mention of check_plain is the function itself.
Comment #91
XanoComment #92
grom358 CreditAttribution: grom358 commentedreroll
Comment #94
grom358 CreditAttribution: grom358 commentedTypo when rerolling. fixed.
Comment #95
grom358 CreditAttribution: grom358 commentedComment #96
grom358 CreditAttribution: grom358 commentedComment #98
alansaviolobo CreditAttribution: alansaviolobo commentedComment #99
grom358 CreditAttribution: grom358 commentedComment #100
grom358 CreditAttribution: grom358 commentedsimple reroll
Comment #101
webchickGetting this in while it's hot!
Committed and pushed to 8.x. Thanks!