Updated: Comment #13
Problem/Motivation
The search result templates split apart the OL and the LI parts of an item list. This goes against the principal of keeping single HTML elements in single template files, one of our principles for cleaning up the theme layer.
Proposed resolution
Remove search-results and use the standard item_list theme template/function, with a suggestion so it can be uniquely themed for search results purposes.
Remaining tasks
Latest patch in #13 is perfect :) However it is currently blocked by:
#2105609: Convert search_embedded_form_form to a Controller
#1987806: Convert search_view() to a new style controller
#2120807: Add empty option to item_list
User interface changes
None.
API changes
There will be no more theme('search_results'), but only theme('search_result'). Similarly, the preprocess and other hooks will only apply to search_result.
This means only one template for themers to modify and only one preprocess hook for modules to use if they want to affect how search results are displayed, rather than two, which should be simpler. Themes can still have good control over the output via the theme suggestions on the item list that displays on the results page.
Related Issues
#1898448: search.module - Convert PHPTemplate templates to Twig
Comment | File | Size | Author |
---|---|---|---|
#68 | 1926344.68.patch | 8.33 KB | alexpott |
#54 | noresults-54.png | 38.53 KB | jhodgdon |
#54 | results-54.png | 48.56 KB | jhodgdon |
#54 | interdiff.txt | 3.49 KB | jhodgdon |
#54 | 1926344-54.patch | 8.33 KB | jhodgdon |
Comments
Comment #1
chrisjlee CreditAttribution: chrisjlee commentedWould this cause it to be more difficult in case themers wanted to seperate these templates out?
Forgive my ignorance. I'm just starting to try to understand the twig system.
Comment #2
krystalcode CreditAttribution: krystalcode commentedI've merged the 2 template files into one and the 2 preprocess functions into one, please review.
I've kept the function that prepares the results as a separate function, is there a naming or placement convention for it? (rather new to Drupal here)
@chrisjlee, with Twig you would be able to separate the templates without needing to alter the php code, you would do
and the variable would be available in the search-result.html.twig file that you would create. I'm not sure how you would include the new template file with the way Twig is set up in Drupal, the above didn't seem to work for me.
Patch created as part of Florida DrupalCamp 2013
Comment #4
ldpm CreditAttribution: ldpm commentedComment #5
ldpm CreditAttribution: ldpm commentedAfter some exhaustive research, it looks like this could be a problem with the test. The search_extra_type module has some hooks in it that may be problematic at line 58: search_extra_type_search_page. Continuing to investigate if the other failures might have to do with the test.
Comment #6
jhodgdonI am working on this.
Comment #7
jhodgdonHere is a completely new patch. I ran most of the search module tests and I think this should work. I didn't really start from the patch above, so an interdiff is not all that useful.
Comment #7.0
jhodgdonadded related issue
Comment #8
jhodgdonI just added an issue summary.
Comment #9
jhodgdonNote that if we do not decide to go this route, we need to do
#1517032: Update search-result.tpl.php code comments to reflect new $info_split default keys
for 8.x.
Comment #10
jhodgdonAlso this will conflict with
#2105609: Convert search_embedded_form_form to a Controller
so whichever gets in first, the other will need a new patch.
Comment #11
markhalliwellThis looks great! I think we should take the consolidation of this issue a little farther though and just use an item list:
item_list__search_results
. I'm going to create an issue to extend the item list function to include an "#empty" option like theme_table() does.Comment #12
markhalliwell#2120807: Add empty option to item_list
Comment #13
jhodgdonOK.
Here's a completely new approach (again, and interdiff to the previous patch would not be useful).
This patch depends on 3 issues being taken to completion, so it won't apply now and I'm leaving this at "needs work" for the moment. These are:
#2105609: Convert search_embedded_form_form to a Controller
#1987806: Convert search_view() to a new style controller
#2120807: Add empty option to item_list
The idea here is that the search-results.tpl.php file is replaced by using a theme('item_list') with theme suggestions. Once #2120807: Add empty option to item_list is done, theme('item_list') allows us to pass in the "empty" text (for the no search results case), so theme overrides can be used to customize the output as desired, for both the has and doesn't have results cases. Which was basically the purpose of the results template.
The search-result template is retained, but the LI wrapper is removed. So it just formats each result items, and the list of them is themed with an item_list theme function.
One other change: the markup for the no results case is changed slightly: there's a heading of Search Results even if there are no results.
I'm going to go ahead and upload this patch, and then I'll run the Search module tests locally and see what happens.
Comment #14
markhalliwellLooks great! Thanks @jhodgdon! Changing status to postponed since this issue is dependent on other issues. Updated issue summary as well.
Comment #14.0
markhalliwelladded issue summary
Comment #14.1
markhalliwellUpdated issue summary.
Comment #14.2
jhodgdonupdate plans
Comment #15
jhodgdonThe dependent issues are finally all taken care of. So, I'm un-postponing this issue, and if the patch doesn't start its test, I'll ping it.
Comment #16
jhodgdonLovely. Looks like I'll have to re-upload the patch, and then file a D7 d.o regression issue because there is no way to launch a test on the previously-uploaded file.
This is the exact same patch file as in #13.
Comment #18
jhodgdonHuh. It doesn't look like this patch is attempting to queue for test either... any ideas?
Comment #19
jhodgdonOK it is just slow but this needs a reroll. :(
Comment #22
star-szrRerolled.
Comment #24
jhodgdonThe tests that are failing probably need an update. I believe they are failing because "Search Results" used to only be visible if there was at least one result, and now "Search Results" is always visible. I'm not sure when those tests were added, but they need some attention.
Comment #25
jhodgdonActually, I take it back. It looks like the test is failing because the title "Search Results" is not being displayed on an actual search results page. This is probably an actual bug.
I don't have time to investigate this week, so if someone else wants to fix this one, that would be fine. Otherwise, I may be able to get back to it next week.
Comment #26
jhodgdonOh wait. The text changed from "Search results" to "Search Results". This should fix it.
Comment #27
star-szrSo the 'Search Results' title is displayed even if there are no results, that's probably okay. But the way things are set up now we have two
<h3>
's in a row which seems bad. Search Results before this patch was a<h2>
which is more difficult to achieve with theme_item_list() of course. Not sure the best way forward but I think that needs to at least be discussed.Can we document here that theme_item_list__search_results() (and maybe them_item_list__search_results__PLUGIN_ID()) can be overwritten to change the outer markup? Or document that this template is rendered within an item_list?
Comment #28
jhodgdonThe headers are no worse than the mess they were in before this change... fixing them might be possible...
Documentation on the result twig sounds linke a fine idea.
Comment #29
star-szrThis might be a silly idea but can we just make the "Your search yielded no results" a p tag?
Comment #30
jhodgdonThe problem is that it's actually a header for other information that comes after, but we could possibly make it an H4.
So... Let's step back and take a look at the markup.
Without the patch, we currently have in D8 is something like this if there are no results:
And if there are results:
With this patch, this changes to:
And if there are results:
So it looks like the correct fix for this patch, which would preserve as much as possible what was being done before, would be to put the Search Results header into an H2 instead of H3. The reason it changed to an H3 was because we are putting this into theme_item_list() as the #title attribute. So we just need to do the title outside the list. Having it be an H3 is wrong for this case.
Attached patch fixes those Search Results headings to be h2, and also adds documentation as suggested above.
Comment #31
jhodgdon30: 1926344-30.patch queued for re-testing.
Comment #34
jhodgdonLooks like this one needs a reroll.
Comment #35
jhodgdonThis is a straight reroll of the previous patch. Maybe we could get it reviewed?
Comment #36
star-szrI would love to!
Comment #39
jhodgdonDoh. This should work better. Interdiff - from last patch, in SearchController:
Whoops. Guess I should have at least tested the reroll manually. Good thing we have tests. :)
Comment #40
star-szrI compared markup and it's looking good overall! I think the only thing we need to fix is the classes we are losing which will be helpful for styling.
search-results
and<plugin_id>_search-results
disappear.Before:
After:
So I think we need to add these back to the item-list div or more ideally to the ol.
Did profiling for fun and performance looks comparable.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52e417f8e04a5&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52e417f8e04a5&...
Comment #41
star-szrTagging as novice to add the class to the OL. Hint: look at theme_item_list API docs :)
Comment #42
maggo CreditAttribution: maggo commentedSearch results, now with classes :)
Comment #43
maggo CreditAttribution: maggo commentedPatch added
Comment #44
star-szrThanks @maggo, that looks good at a glance, interdiffs are especially helpful in cases like this but I diffed the two patches and the changes look good.
We just need some trailing/dangling commas here per https://drupal.org/coding-standards#array.
Like this:
Comment #45
star-szrI forgot to mention this in my review but we shouldn't be referencing theme() like this in documentation, especially given #2173655: Refactor theme() to _theme(); make it a private API to discourage module developers from circumventing the renderable build system.
'#theme' => 'item_list'
would be more appropriate.Comment #46
maggo CreditAttribution: maggo commentedDone!
Comment #47
star-szrThanks @maggo.
This line was fine - please revert this change and make the requested change in search-result.html.twig instead.
Almost! We need two more trailing commas on the lines that only have a closing parenthesis.
Comment #49
RainbowArrayI can work on this change.
Comment #50
RainbowArrayAdded a patch with the changes Cottser suggested, along with an interdiff.
Comment #51
star-szrThanks @mdrummond!
After reviewing this again a couple things stood out to me.
1.
I'm not exactly sure why we're changing the "Search results" interface text to "Search Results". Minor but it is a change that seems unrelated.
2. Now that the search results header is split out, we could hide it when there are no search results, this is the current behaviour and we can maintain it. Then the only difference will be that 'Your search yielded no results' will be an h3 instead of an h2 which is probably fine :)
Before:
After:
Comment #52
star-szrOh, and I forgot to mention the class names on the ol are not quite right.
Before:
After:
So this code should just be adding -results, not _search-results to the plugin ID.
Comment #53
jhodgdonWow, thanks for all the work on this! It looks like we just need a couple more small changes to the current patch. Is anyone up for making those changes or should I step back in?
Comment #54
jhodgdonThis new patch addresses the issues in #52 (classes on the OL are now search-results node_search-results) and #51 (see new screenshots, made with Stark theme).
With results:
No results:
Comment #55
star-szrThanks @jhodgon!
This looks great. I really like how this simplifies overriding search results and leverages item_list.
One idea for a small and Novice-able follow-up would be to rename search.pages.inc to search.theme.inc and update the @file now that it only contains theme API hook implementations (preprocess and suggestions).
Love the docs change here!
Comment #56
webchickCommitted and pushed to 8.x. Thanks!
Comment #57
alexpottThis broke head so I've reverted it.
Committed 580dd44 and pushed to 8.x. Thanks!
It broke because it's possible to have the no result test on a page with results :) See below.
Search results
Test page text is here
Dummy title
Dummy search snippet to display. Keywords: foo
Conditions: Array
(
[search_conditions] =>
)
Your search yielded no results.
Comment #58
alexpott54: 1926344-54.patch queued for re-testing.
Comment #60
jhodgdonWhoops! Apparently conflicted with another search.module patch. I'll see about the failures.
Comment #61
jhodgdonComment #62
jhodgdonCottser pinged me in IRC. Apparently the problem really was that a commit to #1939062: Convert theme_item_list() to Twig around the same time broke this patch. The plan is to fix that issue and then this one should be able to test green.
Comment #63
webchickOk sorry about that, #2191323: item-list.html.twig always shows empty text is now committed, so we should be able to proceed here.
Comment #64
star-szr54: 1926344-54.patch queued for re-testing.
Comment #65
jhodgdonGreat! OK the next thing is to retest the patch above and see if that fixed the test failure or if something needs to be refactored.
Comment #66
jhodgdonOh, cottser just did that, crosspost!
Comment #67
jhodgdonTests now pass again, since that other issue was fixed, so back to RTBC.
Comment #68
alexpottThis patch conflicted with #2183923: Break the circular dependency in EntityManager. Considering I reverted it here is a reroll.
Comment #70
alexpott68: 1926344.68.patch queued for re-testing.
Comment #71
alexpottBack to rtbc - random test fail.
Comment #72
alexpottCommitted 4fb874b and pushed to 8.x. Thanks!
Comment #73
star-szrThanks @alexpott!
Comment #74
jhodgdonHooray!