Problem/Motivation
See #3566536: [meta] eliminate core .module files.
Way back in #1868772: Convert filters to plugins filters were converted to plugins. But these mostly consist of one line process methods.
public function process($text, $langcode) {
return new FilterProcessResult(_filter_autop($text));
}
public function process($text, $langcode) {
return new FilterProcessResult(_filter_html_escape($text));
}
Proposed resolution
Deprecate the following procedural functions and move their login in the corresponding filter plugin:
- _filter_url()
- _filter_url_parse_full_links()
- _filter_url_parse_email_links()
- _filter_url_parse_partial_links()
- _filter_url_escape_comments()
- _filter_url_trim()
- _filter_autop()
- _filter_html_escape()
- _filter_html_image_secure_process()
No replacement is provided.
Remaining tasks
None.
User interface changes
None.
API changes
Above procedural code is deprecated.
Data model changes
None.
Issue fork drupal-3226806
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
longwaveNeed to add deprecations etc if we are going to do this, will wait to see if anyone else thinks this is a good idea first. Doing this removes ~150 lines of procedural code from filter.module.
Comment #4
joachim commentedLooks like a good idea to me.
Functions that begin with an underscore were always considered as private/internal to Drupal, so I don't think we need to preserve these.
Comment #5
longwaveComment #7
claudiu.cristeaI think they should be deprecated, not removed. As they are publicly available, 3rd-party may using them.
Comment #11
longwaveAgree that we have to deprecate, several contrib.modules call _filter_autop at least, I didn't check the others but we should be consistent.
http://grep.xnddx.ru/search?text=_filter_autop&filename=
I guess the question now is do we move the functions pretty much as-is to static methods, so contrib can call them more easily?
Comment #12
longwaveComment #13
joachim commented> I guess the question now is do we move the functions pretty much as-is to static methods, so contrib can call them more easily?
They were supposed to be private functions! It was clearly documented in D5/6/7 days that functions starting with an underscore are private!
Comment #14
longwaveDiscussed with @joachim in Slack, we decided that instead of exposing the filters as static methods any callers should instantiate the plugin they require via the plugin manager, e.g.
We could perhaps shorten this to
Comment #15
joachim commentedRebased.
Deprecations still to do.
The preg_replace() callbacks such as _filter_url_parse_full_links() should be deprecated too.
Comment #16
claudiu.cristeaMRs base branch should be changed to "main"
Comment #18
claudiu.cristeaAdding to #3566536: [meta] eliminate core .module files
Comment #19
claudiu.cristeaLet's see
Comment #21
claudiu.cristeaComment #23
joachim commentedYup, I had a go at rebasing the old MR, and I hit a conflict which was caused by changes in the code the MR was deleting. IMO that's where resolving gets risky, because you're comparing two big chunks of code to check nothing was lost. Better to start from scratch.
Comment #24
claudiu.cristeaUpdated IS. This is ready for review.
Comment #25
claudiu.cristeaComment #26
joachim commentedI would have the deprecated functions call the plugin, so the code is only in one place.
Comment #27
joachim commentedAlso, I thought it was a bad thing to inject the container directly into a class.
Would the better pattern not to get the parameter value and pass that to the constructor?
Comment #28
longwave#3558292: Support passing container parameters with the Autowire attribute in AutowireTrait and AutowiredInstanceTrait would make #27 cleaner.
Comment #29
claudiu.cristeaThe plugin expects also a language. I preferred not to touch. But, we might pass the default language
Comment #30
joachim commentedWith the code in two places, it creates an extra maintenance burden until we remove the deprecated functions.
Comment #31
claudiu.cristeaOK, I prefer to block on #3558292: Support passing container parameters with the Autowire attribute in AutowireTrait and AutowiredInstanceTrait
Ok, ok... Let's do it when this is unpostponed
Comment #32
claudiu.cristeaComment #33
claudiu.cristeaComment #34
claudiu.cristeaThe blocker was merged. I'm looking into this...
Comment #35
claudiu.cristeaAddressed the remarks. Ready for review
Comment #36
nicxvan commentedI think this is almost ready.
I think these should be for removal in 12 since they are all underscore.
Comment #37
nicxvan commentedI think this is ready!
I confirmed the deprecation versions are correct and match.
The functions call the correct plugins or retain the logic if appropriate.
This is more complex than a few others and a bit unique, but this seems like the way to do with with minimal disruption.
I also don't think breaking up the functions really makes this that much easier to review is four plugins basically impunity or adding methods.
Comment #38
nicxvan commentedRebased since the other Filter issue just got in, it was clean so leaving RTBC
Comment #39
amateescu commentedReviewed :)
Comment #40
claudiu.cristea@amateescu, thank you for review. Addressed your remarks
Comment #41
nicxvan commentedAll of @amateescu's comments have been addressed, the new split of escapeComments and unescapeComments actually makes this a lot clearer as well, my follow up comments have been addressed and the cleanups look good!
Comment #42
larowlanJust one minor nit, fine to self RTBC afterwards.
Comment #43
claudiu.cristeaSet as RTBC as per #42
Comment #44
amateescu commentedWe need a 11.x MR here, let's create it before the commit to main this time :)
Comment #46
nicxvan commentedDone!
Comment #49
amateescu commentedCommitted and pushed ec8c056 to main and 0347262 to 11.x. Thanks!