Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
18 Sep 2013 at 17:01 UTC
Updated:
29 Jul 2014 at 22:56 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
larowlanI think there's already an issue for this
Comment #2
larowlanCheck in forum module perhaps
Comment #3
larowlanOh, you split this from #1938906: Convert forum theme tables to table #type, carry on :)
Comment #4
joelpittetWhile it feels a bit dirty to put markup back into PHP:S This is probably for the 'greater good'...
This removed the dependency of _theme_table_cell call and tablesort from the forum module, also let's the #theme => table do the zebra and build the headers.
So if this can get in, the #theme=>table to twig can be simplified a bit and remove the forum related code and @todo from the patch.
Comment #5
joelpittetTagging.
Comment #6
rteijeiro commentedIt seems that the patch removed topic_id and header variables:
Comment #7
joelpittet@rteijeiro re #6 That looks like a caching issue. Delete /sites/default/files/php to remove the compiled twig files. I'm sure that it because there is no topic_id in the entire core after this patch is applied.
Comment #8
rteijeiro commented@joelpittet: You are right. Tried with a clean installation and works like a charm ;)
It's a RTBC for me and patch still applies!!
Comment #9
joelpittetThank you for the RTBC:) I think we still need to confirm the markup is identical to before so I didn't accidently break. It would be great to see an HTML diff for forum_topic_list
Steps to compare:
/forum/1and copy the HTML/forum/1and compareComment #10
rteijeiro commentedJust compared markup before and after patch apply.
The only one difference is the "active" class in the replies cell:
<td class="replies active">It's still a RTBC :P
Comment #11
joelpittetThank you @rteijeiro!
RTBC++
Comment #12
alexpottPatch no longer applies.
Comment #13
joelpittetRe-rolled
Comment #14
markhalliwellWhy do we still have a template file for this then?
Comment #15
markhalliwellTo clarify:
If the "form_list" theme function is really just a "table" in disguise, then whatever is calling this theme function should just return

'#theme' => 'table'in the render array. Which means this special theme function can be removed entirely. We need to stop doing:edit: Which in Twig the equivalent in this case would be:
{{ table }}.Comment #16
joelpittet@Mark Carver probably don't need one... but not sure exactly how to let it still be themable. I saw steveoliver and a few others use something like table__forum_topic_list to provide a theme suggestion... but I think that only works for 'type' => 'table'? And 'type' => 'table' seems to be really slow right now and a pain to build out... @see #1938926-29: Convert simpletest theme tables to table #type
So any suggestions? My main concern is that this is a blocker for theme_table converted to twig as it has the hard-coded dependencies for the table sorting. So all this table needs is the ability to sort which theme_table has and it's faster.
Comment #17
joelpittetMoving this to our consolidation meta #1804614: [meta] Consolidate similar twig templates and properly use theme suggestions in core
Going to make helper functions and drop forum_list and forum_topic_list templates.
Comment #18
c4rl commented@joelpittet #17 What do you mean by "helper functions?"
To me, it seems like most things here in forum_theme() are all sub-calls of #theme:forums, which means we can simply consolidate everything into a single callback. If this callback is complicated (and it could be) it may justify providing a template after all for the entire thing instead of having some incredibly verbose #theme:table. So, let's consider consolidating everything into 1 template as well as consolidating everything into something that #theme:table can handle.
Make sense? :)
Comment #19
markhalliwellTaking over this one to provide an example of why one one line templates are bad and how we should utilize render arrays the way they're meant to be used.
Comment #20
joelpittetComment #21
markhalliwellComment #22
star-szrJust cleaning up the title slightly, don't mind me.
Comment #23
joelpittetI have a feeling forum has no render tests... but anyways, here's a partial patch, @Mark Carver let me know if this goes in the direction you're looking for?
Comment #25
c4rl commentedThis isn't comprehensive enough. As I explained in #18 *all* theme callbacks with the exception of #theme:forums are useless:
Willing to hear arguments to the contrary. :)
Comment #26
c4rl commentedTaking a shot at this.
Comment #27
c4rl commentedAfter inspecting the real purposes of forum_theme(), I discovered that there were really two fundamental callbacks: #theme:form_list and #theme:forum_topic_list. The manner in which #theme:forums was being used was fairly strange and I elected to change that behavior for this patch.
So, #theme:forums, #theme:form_submitted, and #theme:forum_icon have been removed as well as #theme:forum_form and _theme_table_cell().
This takes a completely different approach than previous patches, so I don't think an interdiff is particularly useful.
Comment #28
markhalliwellPatch is empty
Comment #29
c4rl commentedD'oh
Comment #31
markhalliwell@c4rl, the
forum_listandform_topic_listtheme hooks are still ultimately tables. It doesn't make sense to create separate theme hooks and should instead dotable__forum_listand just create separate template suggestions liketable--forum-list.html.twigfor the custom forum markup.Given that we cannot currently preprocess theme suggestions until #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() is in, perhaps you can simply provide a generic
hook_preprocess_table()preprocess and check the theme hook in the $variables to catch preprocessing until that gets in?Comment #32
c4rl commentedSpoke with @Mark Carver about this in IRC.
We have two options here:
forum_listandforum_topic_listas-is with duplicate markup to whattableprovides (i.e., what I was suggesting in #29.table, but that is currently blocked by #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() if we want to do it right.Aside from the specifics of which hook to use for those two functions, I'm hoping the general approach of #29 is better. In the long-term, these being lists should probably be somehow converted to work as a view (@todo link/create issue?) since they indeed fall into the fabled realm of "lists of stuff."
So I'm going to dive-in to #2035055: Introduce hook_theme_prepare[_alter]() and remove hook_preprocess_HOOK() for now.
Aside from fixing my exceptions in #29 this will also need rebase now that #2028113: Make forum module css a library is in. :)
Comment #32.0
c4rl commentedUpdated issue summary.
Comment #33
joelpittet29: drupal-2092343-29.patch queued for re-testing.
Comment #35
joelpittetNeeds Reroll
Comment #36
joelpittetOk here's a compromise. The interdiff is from #2092343-23: Consolidate forum.module and remove call to _theme_table_cell() within template_preprocess_forum_topic_list()
I fixed the pager missing, and removed the helper function as well. I didn't convert forum-list.html.twig because that table is a bit more complicated to get right and probably should be it's own issue, but this patch gets the _theme_table_cell() call out and removes theme function for #theme=>table and makes it a suggestion instead.
I think this is good enough for this patch and make another follow-up issue for forum-list to #theme=>table or #type=>table...
Comment #38
joelpittetNeed to set a default variable for the pager.
Comment #39
star-szrThis looks like good cleanup to me, if it's a table let's treat it like one.
Two things stood out to me:
1. We need to set
'#responsive' => FALSEin the render array fortable__forum_topic_listto get the markup to match up (the active class mentioned in #10 and alsoresponsive-enabledclass on the table) and importantly also prevent loading extra JS libraries.2. I think we should initialize not just
topics_pagerbut also thetopicsandforumsvariables as empty arrays at the very top oftemplate_preprocess_forums()(especially since we're making it bigger). That would allow us to remove a bunch of unneeded else statements further down, and we could also consider an early return if this condition doesn't evaluate to TRUE:Comment #40
star-szrOne more small thing:
I think
$variables['topics'] = $table;should only be set if there are topics to display.Check the source on /forum and you'll find an extra empty table:
On HEAD it's less empty:
Again an early return might make sense here because if there are no topics then there is no topic pager either and the rest of the preprocess is not needed, including preparing the #theme table render array. The change from HEAD would be that when viewing a forum like /forum/1 with no topics posted we wouldn't get the empty table with headers only. But that's a bugfix IMO:
And I'd just like to acknowledge that yes the global $forum_topic_list_header is yucky but that's not being added here and should be a separate refactor IMO.
Comment #41
joelpittetComment #42
joelpittetComment #43
star-szrWe need to document topics_pager in this Twig template.
Other than that this looks great to me. Here are some profiling results, looking very good!
Default install, enable forum module, /forum:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d3e812c7cf2&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d3e812c7cf2&...
Default install, enable forum module, /forum/1:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d3e93cb560e&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d3e93cb560e&...
Default install, enable forum module, add 26 topics, /forum:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d4b590e6e18&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d4b590e6e18&...
Default install, enable forum module, add 26 topics, /forum/1:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d4b18f32fb6&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52d4b18f32fb6&...
Comment #44
joelpittetSweet performance gain:) Here's the docblock.
Comment #45
star-szrThanks!
Comment #46
alexpott2092343-_theme_table_cell-44.patch no longer applies.
Comment #47
alexpottComment #48
joelpittetRe-rolled.
Comment #49
joelpittetBack to rtbc, the re-roll in 48 was wrong but the diff between that re-roll and the previous patch shows the mistake(change) and i've applied it to this patch.
Comment #52
joelpittet49: 2092343-_theme_table_cell-49.patch queued for re-testing.
Comment #53
star-szrLooks good!
Comment #54
star-szrI guess we might want to add this back, but that's minor.
Comment #55
joelpittetThanks @Cottser, I thought I had that in there. Added back.
Comment #57
joelpittet55: 2092343-_theme_table_cell-55.patch queued for re-testing.
Comment #58
star-szrComment #59
webchickCommitted and pushed to 8.x. Thanks!