Task
Convert filter.module theme functions to Twig templates.
Remaining
- Patch needs review
- Manual testing (steps below)
| Theme function name/template path | Conversion status |
|---|---|
| Converted to #type table (and committed) in #1938904: Convert filter theme tables to table #type | |
| Already converted to #type table in #80855: Add element #type table and merge tableselect/tabledrag into it | |
| theme_filter_guidelines | converted |
| theme_filter_html_image_secure_image | Changed to an alter hook (see API changes section) |
| theme_filter_tips | converted |
| Removed in #1222260: Remove theme_filter_tips_more_info() from core | |
| theme_text_format_wrapper | converted |
Testing steps
- Add an article node (node/add/article)
- The body field should be wrapped in text-format-wrapper.html.twig.
- The set of filter guidelines for each text format should be output by filter-guidelines.html.twig.
- The list of filter tips should be output by filter-tips.html.twig.
- Using the Basic HTML format, click the image button in the editor toolbar and add an image hosted on another site.
- Save the node.
- When viewing the node, the external image you added should be replaced with a red X.
See also /filter/tips.
API changes
The patch removes theme_filter_html_image_secure_image() and replaces it with an alter hook (hook_filter_secure_image_alter()). Part of the Twig conversion is removing theme functions, and unlike other theme functions, theme_filter_html_image_secure_image():
- Doesn't return a string.
- Alters the variables (a DOMElement to boot) by reference.
| Comment | File | Size | Author |
|---|---|---|---|
| #136 | 2014-01-25-remove-debugging-strings.patch | 660 bytes | mikl |
| #131 | interdiff.txt | 943 bytes | star-szr |
| #131 | 1898416-131.patch | 14.02 KB | star-szr |
Comments
Comment #1
c4rl commentedTagging
Comment #2
disasm commentedAttached is a patch
Comment #4
star-szrThanks for all the patches @disasm :)
I applied this one locally and the test failures are legitimate. Didn't poke around too much yet, but this looks like part of the problem:
Twig_Error_Syntax: The function "theme" does not exist in "core/modules/filter/templates/filter-guidelines.html.twig"The line in filter-guidelines.html.twig:
{{ theme('filter-tips') }}From what I can tell we need to create a render array for filter_tips in template_preprocess_filter_guidelines() and then print the render array in the template, see http://drupal.org/node/1920746#render.
Comment #5
kerasai commentedCleaned up a few places that were throwing errors, still going to need further attention.
Let's see how bad the bot chokes on at this point.
Comment #6
kerasai commentedNo matter the results of the automated test, there is still some weirdness. Haven't had a chance to get into the details of why these are happening.
The filter configuration screen as a second table:

Also the markup in the form widget has changed enough to where the javascripty magic to toggle the tips displayed based on the selection is no longer functional.

Comment #7
joelpittet@kerasai nice go at this.
Couple things I noticed. Your template_preprocess functions need to have their $variables referenced
template_preprocess_filter_admin_format_filter_order(&$variables)there should be no more
$output .=left in your template_preprocess after you are done converting. The html tags should be moved to the twig template and the variables should be added to$variables['whatever']so they can be output in the twig as{{ whatever }}theme('table', ...should be converted to@see http://drupal.org/node/1920746
Otherwise nice first go at it. That should help with those screenshots a bit...
Thanks again, cheers!
Comment #9
kerasai commentedI've got a pretty good idea of what's needed to finish this (RTFM) but it'll be a bit before I can get back on it. If someone wants to grab it, that's cool. Otherwise I'll get back at it later this week.
Comment #10
joelpittetComment #11
joelpittetOk
/filter/tipslooks a bit... wrong but the bulk of this works great:) I think this issue may help that ugly bit:http://drupal.org/node/1778624
I added #type table stuff but will post a separate patch just in-case this one doesn't fly.
http://drupal.org/node/1938904
Comment #13
steveoliver commentedJoel: nice work. Some good cleanup and consolidation in here.
Re: the consolidation of
filter_tipsintoitem_list__filter_tips...:i'm a lil torn. Thought 1 is: Do it right the first time. Thought 2: it's consolidation and not conversion, and consolidation may be easier after conversion. Plus, it's filter.module, maybe move on.. :)
In any case, a once-over on the patch:
Nice to see these go in favor of the consolidation of #tabledrag into filter_admin_format_form.
Use new preprocess docblock format: #1913208: [policy] Standardize template preprocess function documentation.
Oh this docblock is all messed up. :)
Preprocess docblock.
remove one \n
I'm guessing this needs a docblock edit.
1. I think we need a @see template_preprocess_filter_guidelines() or whatever the function's called?
2. Remove space from ' #}' at the bottom.
Super-nit: Coding style: lowercase @todo.
Need the ' > 0' in the second, 'tip.list|length > 0'?
@see template_preprocess..., not @see theme_...
Comment #14
star-szrRegarding the super-nit, after the @todo needs to be a complete sentence and therefore start with a capital letter in this case.
http://drupal.org/node/1354#drupal
http://drupal.org/node/1354#todo
Comment #15
joelpittetCleaned up docblocks and preprocess docs and added fixes in from #1938904: Convert filter theme tables to table #type
Not sure which commit will land first though, may have to reroll this one if the other lands first.
Comment #17
joelpittetLet's not have those exceptions... shall we? And I forgot to save the length>0 thing.
Comment #18
star-szrWoot! It's green, nice work @joelpittet! Documentation nitpicks ahead:
These need to end in a period.
Hmm, maybe "Prepares variables for an image DOM element that has an invalid source."?
This @todo needs to be wrapped because it's over 80 characters with the URL.
http://drupal.org/node/1354#todo
s/reimplement/Reimplement
Comment #19
joelpittetCaught a few more too, thanks @Cottser
Comment #20
star-szrI'm thinking we need a .html.twig file for filter_html_image_secure_image, no?
I see the rename and docblock update from theme_filter_html_image_secure_image -> template_preprocess_filter_html_image_secure_image but no .html.twig file.
Comment #21
star-szrAlso this will probably need a reroll now that #1938904: Convert filter theme tables to table #type is in.
Comment #22
joelpittet@Cottser, filter_html_image_secure_image is so weird! it doesn't return anything... not sure how to convert that to twig.
And sweet, didn't even see that was committed:) Will re-roll after I have a bit more idea of what to do with secure image...
Comment #23
star-szrtheme_filter_image_secure_image() is very strange indeed, it's the only theme function that I've seen that doesn't return anything.
As discussed on IRC, I'm wondering if we can change theme_filter_image_secure_image() to a theme_image suggestion like image__secure_image, and move the logic to template_preprocess_image__secure_image. So in theory the output would still be through image.html.twig and would still be themeable by creating image--secure-image.html.twig.
See #1344078-16: Local image input filter in core, theme_filter_image_secure_image() was originally an alter hook.
See #1939068: Convert theme_image() to Twig for the theme_image conversion.
Comment #23.0
star-szrAdd conversion summary table
Comment #24
joelpittetUnassigning, and backing away slowly.
Comment #25
star-szrWill give it a try, thanks @joelpittet!
Comment #26
star-szrTagging.
Comment #27
star-szrI'm hoping to get to this later tonight or tomorrow.
Comment #28
star-szrFirst the reroll (removes #type table conversion as well).
Comment #30
star-szr(Adding JavaScript tag because this touches filter.admin.js)
Especially with theme functions going away, it no longer makes sense to keep theme_filter_html_image_secure_image() as themeable. This patch moves that functionality to an alter hook, which themes can still implement if they want.
theme_filter_html_image_secure_image() is unlike any other theme function that I know of:
API change as well as manual testing steps added to issue summary.
Other changes:
Comment #30.0
star-szrLinkify main #type table issue, add filter #type table issue to related
Comment #32
star-szr#30: 1898416-30.patch queued for re-testing.
Comment #33
star-szrThis is a strange one, assigning to @steveoliver for another review.
Comment #34
steveoliver commentedUpdate: will be reviewing this Thursday, incase anyone else wants to review in the meantime.
Comment #35
steveoliver commentedJust looking at the patch here. Unassigning for someone else to do manual testing. :p
It's always nice to see hook_theme entries die.
Why define $filter_tips_link here? Let's just add to the help array.
I really don't like the look of this, wiping out the class attribute. I'd much rather see an array_diff type approach here.
This is an excellent move here. Nice.
Since the long variable is optional in the sense of the API/theme hook call, I suggest removing 'optional' here. Also, instead of the "Only set the class if the type is long" comment inline below, maybe we note that "...passed-in filter tips contain extended explanations" "...and should receive identifying class attributes..." "i.e. intended to be output..."
If not removed altogether, maybe this comment should read something like "Class attributes are set in preprocess when long is TRUE." or something like that, since this isn't an instruction, but a note about what (class) may or may not exist.
Comment #36
star-szrI'll take care of the changes, thanks for the review @steveoliver!
Comment #37
star-szrReminder to myself - look at #1222260: Remove theme_filter_tips_more_info() from core as well.
Comment #37.0
star-szrAdd testing steps, note API change
Comment #38
star-szrarray_diff didn't work in this case, but I found a nice approach in views_preprocess_html()!
Also tweaked whitespace in filter-tips.html.twig, one line was not indented properly (off by a space) - see the interdiff.
As for this from #35:
I think that is covered by the 'tips' description:
Also changed the drupal_alter() to the new-style \Drupal::moduleHandler()->alter().
Comment #39
star-szrAnd fixing up theme_filter_tips_more_info() replacement per #1222260-18: Remove theme_filter_tips_more_info() from core to use l() instead of #theme link.
Comment #40
c4rl commentedPer #1757550-44: [Meta] Convert core theme functions to Twig templates, retitling to indicate this issue applies to theme_ functions, which are lower in priority than PHPTemplate conversion issues.
Comment #41
intergalactic overlords commented#39: 1898416-39.patch queued for re-testing.
Comment #43
bradwade commentedTrying to reroll 1898416-39.patch.
Comment #44
bradwade commentedRerolled 1898416-39.
Comment #45
bradwade commentedChanging status
Comment #46
hanpersand commented#2: drupal-filter_twig-1898416-2.patch queued for re-testing.
Comment #48
jerdavisrerunning tests
Comment #49
ernie-g commentedattempted to profile several patches, but got errors:
Comment #50
bradwade commentedI incorrectly resolved conflict during rebase of first reroll (44). Rerolled again.
Comment #51
ernie-g commentedprofiling...
latest patch applied properly
Comment #52
ernie-g commentedprofiling output for: 1898416-48.patch
Comment #53
ernie-g commentedMANY APOLOGIES
It turns out, the profiling instructions I received at the DrupalCon Code Sprint was incomplete.
I am going to be re-running all my profiling :-/
Comment #55
ezeedub commentedLooks like #1985528: Convert filter_tips_long() to Controller made the changes in filter.pages.inc unnecessary. Re-rolling without that file seems to apply.
Comment #56
ezeedub commentedComment #56.0
ezeedub commentedRemove sandbox link
Comment #58
joelpittetCouple of nitpicks that could help with some of those errors. @bradwade unassigning you for now, but you are welcome to give this a crack and pick it back up, same to you @ezeedub.
@ernie-g you got profiling results, so thank you for that! Would be great to know what bit's were missing if you care to share so others don't make the mistake.
The hack is no longer needed.
No need to call new Attribute() on $variables['attributes'] because it's lazy instantiated.
Comment #59
drupalninja99 commentedI had to re-roll the patch since you can't apply it to 8.x head. I applied it to an older commit (from May 28) and then do a git pull and fixed a couple of conflicts with head. I wasn't able to figure out how to do an interdiff for this. I will attach and make your edit suggestions in the next comment.
Comment #60
drupalninja99 commented@Joel, I had made the fixes you suggested from #58
Comment #61
joelpittetThank you @drupalninja99 that looks great. Tagging, this should get another round of profiling. I think from what I heard the issue @ernie-g ran into was the missing full node block on the page he was testing, though that isn't really necessary now that all templates are in core.
Also needs manual testing, so if anybody can confirm the markup is what it should be that would be great.
See manual testing steps in the issue summary.
Comment #62
kerasai commentedManual testing complete, markup looked fine and user experiece was as expected.
Notes for the steps listed in the issue summary:
Comment #63
kerasai commentedLooks like we lost a couple tags, adding back.
Comment #64
jenlampton#60: filter-1898416-60.patch queued for re-testing.
Comment #65
jenlamptonexpecting this will fail. tagging for needs reroll
Comment #67
pwieck commentedWorking on reroll
Comment #68
pwieck commentedreroll to current head
Comment #69
pwieck commented#68 Passed and ready for review, testing or rework.
Comment #70
siccababes commentedI checked this out and it looks good. I'm leaving this as needs review because I think this needs profiling.
Comment #71
joelpittetScenario 1
Stark
/filter/tips
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ca5414b31d9&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ca5414b31d9&...
Scenario 2
Stark
/node/add/article
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ca5a4995c23&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51ca5a4995c23&...
Comment #72
joelpittetRemove this @todo, that node can deal with itself.
Remove this as well.
Remove these as well
And this.
Comment #73
drupalninja99 commentedMade changes from #72. I wasn't sure if you wanted to remove the strip tags call or just the @todo doc. I did remove the strip tags call bc I figured it would no longer be needed once the referenced ticket is resolved.
Comment #74
joelpittet@drupalninja99 Not the striptags or you will have to add back in the
check_plain($format->name)to the preprocess because we don't want to ship with less security.Comment #75
drupalninja99 commentedI have added striptags back.
Comment #76
joelpittetGreat thank you @drupalninja99
Comment #77
alexpottNeeds a reroll
Comment #78
drupalninja99 commentedHere is the re-rolled patch
Comment #79
jenlamptoncleaning up tags
Comment #80
adamcowboy commentedI applied the patch and tested it. It worked well!
Comment #81
alexpottIs this change correct? When editing a filter format afaics the id of the table is still
filter-order.Comment #82
eromero1 commentedI downloaded the patch, and, with the help of @jenlampton, ran through all of the steps listed in the "How to test" section. Everything went accordingly, looks great.
Comment #83
star-szrHmm, yeah the JS change seems unnecessary, but needs confirmation.
I think that the reordering of filters got converted to #type table in #1938904: Convert filter theme tables to table #type.
Comment #84
star-szrRegarding the JS change: I looked at the interdiff in #11 and that is where the #type table conversion was started and the JS was changed. The #type table conversion was removed in #28 here after being committed in #1938904: Convert filter theme tables to table #type and in #1938904-3: Convert filter theme tables to table #type the ID was fixed so that the JS didn't need to be changed.
So we need to remove the change to filter.admin.js, and there are a few other clean-ups to be done:
We can remove this unnecessary $output = '' line in template_preprocess_filter_tips(), this is never used.
Extra space after = sign should be removed.
We can remove the "format." prefixes from the documentation of these variables. Indenting in the docblock/api.d.o docs for variables means drill down/"add a dot".
We should document the 'multiple' variable in the docblock.
Comment #85
drupalmonkey commentedComment #86
drupalmonkey commentedTook care of the issue in #84.
Comment #87
joelpittetThank you @drupalmonkey!
Back to RTBC, been profiled @ #71
Comment #88
star-szrOne more thing…
Perhaps I'm missing something but couldn't we just do
$variables['multiple'] = count($tips) > 1;Creating the $multiple variable seems unnecessary.Comment #89
joelpittetAh you're right I think a while back that var had some if check but no longer does, though either it's not needed.
Comment #90
drupalmonkey commentedRemoved the variable assignment per #88.
Comment #92
star-szr#90: filter-1898416-90.patch queued for re-testing.
Comment #92.0
star-szrUpdated issue summary.
Comment #93
star-szrThanks @drupalmonkey! Back to RTBC then.
Comment #94
kim.pepper#90: filter-1898416-90.patch queued for re-testing.
Comment #95
alexpottNeeds a reroll
Comment #96
joelpittetRe-rolled, should be back to RTBC if passes.
Comment #97
star-szrLooks good, thanks @joelpittet!
At this point I'm thinking that there should probably be some test coverage for the refactoring of theme_filter_html_image_secure_image() into an alter hook.
Comment #98
miklRe-roll.
Comment #99
miklComment #101
mikl#98: 1898416-98-filter-twig.patch queued for re-testing.
Comment #103
danquah commented#98: 1898416-98-filter-twig.patch queued for re-testing.
Comment #105
star-szrThe patch shrunk by a few KB so I think we need to look at another reroll.
Comment #106
miklOk, I'm on it.
Comment #107
miklOk, I'm on it.
Comment #108
miklComment #109
miklRe-added missing files.
Comment #110
miklI think we're good here.
Comment #111
robmc commentedComment #111.0
robmc commentedRemove suggested commit message, Dreditor gets it right :)
Comment #112
joelpittet109: 1898416-109-filter-twig.patch queued for re-testing.
Comment #113
joelpittet109: 1898416-109-filter-twig.patch queued for re-testing.
Comment #115
robmc commentedComment #116
kim.pepperComment #117
joelpittetRe-rolled.
Comment #118
sunGlad to see this!
A few questions:
The original intent was to have a single implementation for "theming" a placeholder image only, and the theme system was the natural place to put it.
However, I agree that it's rather an abuse of a theme function, so the conversion into an alter hook is OK for now.
We can think about better ways in a follow-up issue, if necessary.
Do we really need a wrapping paragraph here? That paragraph will get into your way when you try to re-style the text format selector widget.
Can we remove the paragraph? The .filter-help class on the container should be sufficient?
As a themer, the conditional output of the wrapper elements (and lack thereof) always resulted in a unexpected bad surprise when testing the design as anonymous user.
I wonder whether we want to remove these 'multiple' conditionals as part of this conversion to (1) simplify the template and (2) prevent nasty surprises?
The 'multiple' condition here looks wrong to me -- the wrapping container + heading is only used for the long filter tips; i.e., the condition should be 'long' instead.
That said, it would be great if we could split these two completely different representations (short/list vs. long/page) into two separate templates. Having them in a single never really made sense to me.
The (short) filter tips are just a list.
Following similar image/link conversions, shouldn't we use the regular list template instead of inventing a new one?
Obviously, this case is a bit special, since the resulting output/markup depends on the data being passed in (it's only a list if there are multiple tips). I don't know how we handled such cases elsewhere?
Comment #119
star-szr@sun - thanks for your review and especially your feedback on the removal of theme_filter_html_image_secure_image() :)
My gut feeling at this point is that points 2-5 are a bit out of scope for a straight conversion that's purposefully not changing any markup. I would rather those changes be discussed in a follow-up issue, and for the record they all sound like very good ideas to me.
Comment #120
star-szrGoing to see about adding some test coverage for the new alter hook.
Comment #121
star-szrJust wanted to mention that #5 from #118 sounds along the lines of #1778624: rework theme_filter_tips to use the new Attributes, and call theme('item_list) while we're at it so maybe it can be handled there. For the rest I can open a follow-up issue.
Comment #122
star-szrWe already have test coverage for the alter hook in \Drupal\filter\Tests\FilterHtmlImageSecureTest::testImageSource(). Attaching a failing patch that shows what happens when the alter hook is removed.
So with that out of the way I decided to do some manual testing and profiling and review the patch again.
I manually tested /filter/tips and /node/add/article and compared markup via visual diff and DaisyDiff.
There were a couple slight discrepancies in the markup, fixed here (one of which is the removal of the wrapping paragraph mentioned in #118.2). I also noticed that we don't need filter.pages.inc at all (it just contained the now defunct theme_filter_tips()) so that's gone, and cleaned up a couple references to theme_filter_tips() as well.
The follow-up issue to discuss @sun's points in #118 is #2167277: Update filter.module markup and templates.
And below is some fresh profiling data, looks good to me!
/node/add/article
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52c96d7c36f9e&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52c96d7c36f9e&...
/filter/tips
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52c96b69a1c07&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52c96b69a1c07&...
Comment #123
star-szrUpdate conversion status table.
Comment #125
joelpittetReviewing the code, this is looking really good and the profiling is fairly decent too.
One thing I spotted:
striptags != checkPlain. Closest would be |escape but I've yet to compare the two for their merits. Probably better to set checkPlain in the preprocess?
Comment #126
star-szrSounds good.
Comment #127
star-szrThe check_plain() was already there in preprocess, since that's deprecated now I changed it to String::checkPlain() (new hunk anyway so fair game). I'm not sure where the striptags came from because it wasn't there before as far as I can see:
Comment #128
joelpittetGreat, had another look at this patch and I think it's now good to go. Markup comparison + Profiling + Code Review + Testbot = RTBC
Comment #129
star-szrPosting markup before/after, should have done this above. Posting as files because they're pretty big chunks of markup.
Comment #130
star-szrI was wrong, the escaping in filter-guidelines needs another look.
Comment #131
star-szrUpdated patch to add necessary escaping.
I checked Twig_Extension_Core::twig_escape_filter() which is what the escape filter (
{{ string|escape }}) goes through.Relevant code path:
Where $charset is the default, UTF-8. So it looks like escape is a safe substitute for String::checkPlain() with the only difference being the addition of ENT_SUBSTITUTE:
So here's a patch that does that and also clarifies that format.name is potentially unsafe.
Comment #132
joelpittetGreat so it's String::checkPlain()++
Back to RTBC
Comment #133
webchickGreat work!
Committed and pushed to 8.x. Thanks!
Comment #134
mparker17I'm a noob and was interested in finding out what replaces theme_() functions in D8 so I decided to read the patch for this issue, and I noticed these lines:
My initial impression is that these were added for debugging, but they appear to have been committed to core. I'm going to assume this was unintentional and mark this as "Needs work". Sorry :( Feel free to change it back to "Fixed" if these were intentionally left in.
Comment #135
miklmparker17: you are correct, it seems this was missed when comitting. Good catch. I'll make a patch to remove them.
Comment #136
miklHere's a patch to remove the debugging strings (or whatever they were).
Comment #137
star-szrMy fault! I was using that to debug the sanitization. Thanks @mparker17 and @mikl.
Edit: crossposted. We don't normally RTBC our own patches, but +1 to RTBC.
Comment #138
star-szrComment #139
mparker17+1 to RTBC... I've applied the patch and it does remove all
t('hey hey')lines from core.Comment #140
webchickHa. I am clearly losing it. ;P Good catch!
Unfortunately not back from testbot yet (in fact, not even queued) so I'll check again tomorrow.
Comment #141
mparker17136: 2014-01-25-remove-debugging-strings.patch queued for re-testing.
Comment #142
mparker17Yay, it appears to have passed testing!
Comment #143
webchickThere we go. :) Thanks for the quick turnaround, and for catching it in the first place!
Committed and pushed to 8.x.