Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Issue #1898448 by julien, drupalway, podarok, jenlampton, steveoliver, joelpittet, jwilson3, chrisjlee, Cottser | c4rl: Convert search module to Twig.
Task
Use Twig instead of PHPTemplate
Twig sandbox: http://drupal.org/sandbox/pixelmord/1750250
Remaining
* replace all tpl.php files with .html.twig equivalents
* replace all theme functions with .html.twig equivalent templates
* add new preprocess functions for the .html.twig equivalent templates
* update all hook_theme definitions
To test this code...
1) create some content
2) build your search index by running cron
3) search for some content to see that your search results are running through both search-results.html.twig and search-result.html.twig
Related
#1757550: [Meta] Convert core theme functions to Twig templates
Comment | File | Size | Author |
---|---|---|---|
#36 | interdiff.txt | 652 bytes | chrisjlee |
#36 | 1898448-36.patch | 11.85 KB | chrisjlee |
#32 | interdiff.txt | 611 bytes | chrisjlee |
#32 | 1898448-32.patch | 11.85 KB | chrisjlee |
#31 | 1898448-31.patch | 11.84 KB | chrisjlee |
Comments
Comment #1
c4rl CreditAttribution: c4rl commentedTagging
Comment #2
bharat83 CreditAttribution: bharat83 commentedComment #3
bharat83 CreditAttribution: bharat83 commentedComment #4
piers.warmers CreditAttribution: piers.warmers commentedLooking into: DrupalCon Sydney Sprint.
Comment #5
chrisjlee CreditAttribution: chrisjlee commentedpatch attached
Comment #7
chrisjlee CreditAttribution: chrisjlee commented#5: 1898448-search-twig-4.patch queued for re-testing.
Comment #9
star-szrThanks for this @chrisjlee!
Converting the theme() calls to render arrays (per http://drupal.org/node/1920746#render) should fix the exceptions, the 'pager' variable in preprocess would be NULL if no pager was to be rendered.
The remaining failures are legitimate and they are because the help text is missing (see search-results.html.twig). I added that as a temporary @todo but that will need to be fixed in this issue.
The only other changes I made were removing one extra newline, and removing spaces around the 't' filter.
Comment #10
star-szrComment #11
star-szrDiscussed briefly with @steveoliver, let's put the help text in the preprocess for now and revisit later. This should pass testing.
Comment #12
chrisjlee CreditAttribution: chrisjlee commentedNo problem! Awesome it passed.
Thanks for your help. This helps me figure out the patches.
Comment #13
jenlamptonThanks guys, this is a great start! A few comments:
1) In the .html.twig template comment docs we need to remove any mention of variable type, since front-end devs won't need to know what an array or string is anymore. It might be worth reading our coding standards to get up to speed on all these little nuances :)
should become
and
should become
2) We decided to remove all instances of "is defined" from the checks, and will also only define variables as needed. That means that
should become
We changed our mind about that a few times, so it's not uncommon to find lots of instances of "is defined" in the sandbox, but we need to remove them in the core patches.
3) All instances of render() and similar need to be removed from templates. This means that
should become
If we can make these small changes, I think this patch looks great. I'm going to create a follow-up issue about combining these two templates into one though, since we are splitting the OL and the LI tags by doing it this way, and that goes against our new principles for the Drupal 8 theme layer.
edit: Follow-up issue created at #1926344: Consolidate search-result.html.twig and search-results.html.twig
Comment #14
joelpittetRe-rolled
Comment #15
jenlamptonThis is much better :)
I think we still need to get rid of the docs that mention that info_split is a keyed array.
Long term, we should aim to get rid of info_split entirely. We can nest each one of the sub-items within info directly to make the info variable drillable, so printing
{{ info }}
will work exactly as it does now, but printing{{ info.type ]]
should print only the type, as we do currently by printing{{ info_split.type }}
. But I think that is too much for this first patch :)For now, how about we just move the mention of info_split lower in the docs right before we explain what it contains? Something more like...
The @todo in here will remind us to clean this up later as we get to #7, Cleanup of previous preprocess functions.
Also, I missed this in the last review, but the docs still say that these templates contain definition lists which is not the case anymore, so we should correct that as well.
in search-results.html.twig:
should become
And in search-result.html.twig:
should become
Comment #16
chrisjlee CreditAttribution: chrisjlee commentedJennifer:
Thanks for the helpful comments and detailed changes.
Comment #17
star-szrThanks @chrisjlee, the latest patch included changes to UpdateCoreUnitTest.php, quickly rerolled (edited) to remove those hunks.
Minor nitpick (not changed in this patch): the @todo for the info variable is not formatted correctly, see http://drupal.org/node/1354#todo. No colon, and the first word after the @todo should be capitalized.
Comment #18
chrisjlee CreditAttribution: chrisjlee commentedCottser:
Good catch! made those changes
Comment #19
chrisjlee CreditAttribution: chrisjlee commentedWhoops sorry forgot to hit attach.
Comment #20
jenlamptonMore teeny tiny nits :)
In search-result.html.twig
We changed the names of our templates from .twig to .html.twig, so we need to update the docs to reflect that.
In search-results.html.twig
We print
{{ pager }}
in the template, but it's not listed in the Available variables. We should add it.in search.pages.inc we need to clean up the preprocess function docs, now that we have standards :)
and it also looks like the list of elements within $variables was incorrect for template_preprocess_search_result :( let's see if this is a sufficient improvement.
So close guys! :)
Comment #21
joelpittetre-rolled.
Comment #22
star-szrThanks @joelpittet!
The standards aren't quite official yet, but this won't change: the array data type in the @param should be formatted like
@param array $variables
. No surrounding parentheses for the array per http://drupal.org/node/1354#param.Comment #23
chrisjlee CreditAttribution: chrisjlee commentedlike this?
Comment #24
star-szrYup, thanks @chrisjlee!
Comment #26
star-szr#23: 1898448-23.patch queued for re-testing.
Comment #27
jenlamptonThanks Cottser, that one got me twice!
Re-uploading patch from #23 since test bot seems to not want to re-test patches? (it's not actually in the queue)
Comment #28
star-szr@jenlampton - #23 had some random test failures but it did come back green after I re-queued this morning. No biggie :)
Comment #29
jenlamptonTests passing, and... looks fabulous! :) :)
Comment #30
star-szrThis is looking good! Found some more minor docs tweaks, minor enough that this can probably be left as RTBC.
This comment should be re-wrapped at 80 characters, the second line ends too early.
Should this be removed?
These comments needs to end in periods, and in one case (search_results) be wrapped at 80 characters as a result.
Comment #31
chrisjlee CreditAttribution: chrisjlee commented@Cottser Like that? did those changes except this one:
Because i don't really know the answer to that question.
Comment #32
chrisjlee CreditAttribution: chrisjlee commentedSorry realized i just made a small typo.
try this patch instead.
Comment #33
star-szrThanks @chrisjlee! Everything looks good, except one thing…
This comment still needs a period at the end, after 'user'.
Comment #34
jenlamptonOh man, so close I can taste it.
Hmm... Let's leave this for now:
I have been removing lines like these since we will *eventually* be removing the whole process layer, but perhaps it's premature to remove them in these initial patches, since this function still exists. We can roll the removal of all these @see lines into the patch that removes that function. That should be fun :) Dibbs!
@chrisjlee do you want to do the honors of adding the final period as per #33?
Comment #35
chrisjlee CreditAttribution: chrisjlee commentedYes I would love to. Will do that tomorrow!
Comment #36
chrisjlee CreditAttribution: chrisjlee commentedAdded a period. Hooray! I've never been so excited about adding a period!
Comment #37
chrisjlee CreditAttribution: chrisjlee commentedChanged status
Comment #38
jenlamptonAw yeah :)
Comment #38.0
jenlamptonadded to test section
Comment #39
star-szrAdded a commit message to the issue summary based on git blame and sandbox issues. Please edit if I missed anyone :)
Comment #40
xjm#36: 1898448-36.patch queued for re-testing.
Comment #41
alexpott#36: 1898448-36.patch queued for re-testing.
Comment #42
alexpottCommitted and pushed to 8.x. Thanks!
Comment #43
chrisjlee CreditAttribution: chrisjlee commentedComment #45
c4rl CreditAttribution: c4rl commentedPer #1757550-44: [Meta] Convert core theme functions to Twig templates, retitling to indicate this issue applies to templates rather than theme_ functions (though there are no theme_ functions in this module).
Comment #46
c4rl CreditAttribution: c4rl commentedEven though this is committed, do we care about profiling it further?
Comment #46.0
c4rl CreditAttribution: c4rl commentedAdd commit message