Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
block.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 Jan 2013 at 20:38 UTC
Updated:
29 Jul 2014 at 21:48 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
c4rl commentedTagging
Comment #2
duellj commentedAttached patch converts theme_custom_block_block to twig. Doing so introduced an error in BlockTest::testCustomBlock:
Since the theme call was moved to a twig template, white space is added around the body value, causing this assertion to fail. I got around this by adding a trim around the render call:
But maybe there's a better way?
Comment #3
jenlamptoncustom-block-block.html.twig
There is no reason to have a twig template that just prints {{ body }}.
In fact, I can't confirm that this template even does anything at all. Modifying the new template had no affect on the output for me.
We should get rid of this file and make sure that these blocks are rendered via block.html.twig instead. Let's move the preprocessing (which is really just a call to
check_markup($variables['body'], $variables['format']);- not really a pre-processor at all - someplace else, and get rid of the whole hook_theme definition.custom_block_add_list.html.twig - custom block module
It looks like this patch didn't get as far as this template.
custom_block_add_list.html.twig - seven theme
The seven theme also overrides theme_custom_block_add_list so we'll need to provide a template override instead. I think it needs to be in this patch or tests will break. :/
Comment #4
jenlamptonHere's a re-roll of the existing patch, along with the addition of the two new custom_block_add_list.html.twig files and preprocess functions. (one in custom_block module and one in the seven theme)
I'm still not sure what to do about removing theme_custom_block_block, could use some feedback on where/how to kill that one :)
Comment #4.0
jenlamptonAdded To Test section
Comment #5
duellj commented@jenlampton
It's not clear to me that theme_custom_block_block() is even used. Neither the preprocess function nor the twig file are called when theming a custom block, and I removed the theme function and tests pass. It looks like a custom block is using 'custom_block' as it's theme, not 'custom_block_block'. Can we just scrap theme_custom_block_block, or should we change it to theme_custom_block?
If we don't scrap it, the doc headers need to be updated to match the new styles.
Comment #5.0
duellj commentedtypo
Comment #5.1
jenlamptonadded blocked by
Comment #6
jenlamptonNice! I love killing theme functions :)
This version removes theme_custom_block_block conversion, and existence!
Comment #7
duellj commented#6: core-convert_custom_block_to_twig-1898038-6.patch queued for re-testing.
Comment #8
aspilicious commentedNewline needed
Same
Comment #9
jenlamptonnewlines removed.
Comment #10
dasjothis looks quite good, but the seven-specific template file never gets used: core/themes/seven/templates/custom-block-add-list.html.twig
instead the module's twig file was selected, even if the theme was seven: core/modules/block/custom_block/templates/custom-block-add-list.html.twig
maybe that behavior should get filed as a separate bug?
Comment #11
star-szr@dasjo - I think that is #939462: Specific preprocess functions for theme hook suggestions are not invoked.
Comment #12
jenlamptonSeven's override isn't working because its still using PHPTemplate. This issue will need to be postponed until we can get Seven changed over to use Twig.
Comment #13
star-szrDiscussion in IRC led to #1938948: Temporarily allow PHPTemplate themes to use .html.twig templates during Twig conversion. So if we can get that in, then we can un-postpone this.
Comment #13.0
star-szradded note about non-blocking, but delaying, issue
Comment #14
duellj commented#9: core-convert_custom_block_to_twig-1898038-9.patch queued for re-testing.
Comment #16
duellj commentedRerolled so patch applies. Looks like tests were removed from BlockTest, so no longer need the custom handling for the block body.
Comment #17
star-szrThanks for keeping this going @duellj! Some nitpicks ahead:
Looks like the preprocess docblock will need to be updated because of the theme -> preprocess conversion here, see #1913208: [policy] Standardize template preprocess function documentation.
This needs a @file:
@file
Default theme implementation…
This needs a @file also, and the comment should end in a period.
Extra line here can be removed.
Comment #18
joelpittetcleanup from #17
Comment #19
star-szrThanks @joelpittet, the changes look great. Just one tiny fix:
"list of a custom block types" should be "list of custom block types".
Comment #20
joelpittet@Cottser, thanks added a couple more.
Comment #21
star-szrThanks @joelpittet! And here's a couple more documentation tweaks :)
Comment #21.0
star-szrdepends
Comment #22
star-szrMore docs tweaks, tagging for manual testing (steps for testing are up in the summary).
Comment #23
star-szrseven_custom_block_add_list() is converted both here and in #1938848: seven.theme - Convert PHPTemplate templates to Twig. Can we move it so that it's only converted in the seven issue, reconcile any differences, and have manual testers use Stark to test this issue? At a glance it looks like the conversion here is closer to what we need, except for this possible bug:
{% for type in types %}? The docblock doesn't indicate that content is available to this template.Comment #24
joelpittet@Cottser, yes I think
{% for type in types %}is what it should be.Comment #25
shawn dearmond commentedMine. All mine...
Comment #26
shawn dearmond commentedManual testing steps taken:
Also: posted a comment in #1938848: seven.theme - Convert PHPTemplate templates to Twig regarding #23:
http://drupal.org/node/1938848#comment-7305438
Comment #27
shawn dearmond commentedMarking as needs work because of #23.
Comment #28
shawn dearmond commentedUpdated the patch to remove:
And re-rolled a patch for #1938848: seven.theme - Convert PHPTemplate templates to Twig to include those changes.
http://drupal.org/node/1938848#comment-7305534
For the record, the following three patches can be applied cleanly on top of each other:
block: http://drupal.org/node/1898034#comment-7304972
custom_block: http://drupal.org/node/1898038#comment-7305560 (yes, this one)
and
seven: http://drupal.org/node/1938848#comment-7305534
Comment #29
star-szr@Shawn DeArmond - thank you! Happy to see this got split and code is looking good :) Minor documentation nitpick ahead:
We are looping through the 'types' variable, but the variable inside the loop could be called anything (not necessarily 'type') so in the documentation we shouldn't use 'type.link', etc. I would get rid of the first sub-bullet point "type" and roll that into the first point, something like "A collection of all the available custom block types. Each block type contains the follow variables:"
…and then have 'link' and 'description' as the two sub-list items. Basically we want an indent in a list to mean 'add a dot' as much as we can :)
See #1898418-14: forum.module - Convert PHPTemplate templates to Twig for an example.
Comment #29.0
star-szrAdd conversion summary table
Comment #30
jenlamptondibbs.
Comment #31
jenlamptonThe only difference in manual testing was the line breaks and spaces. Adding the spaceless tag should solve this.
Manual testing:
before:
after:
after addition of spaceless tag:
Also made minor docs updates as Cottser suggested. New patch needs quick review.
Comment #32
joelpittetAdded the \n missing from #31
Comment #33
star-szrThis is moving along nicely! Found some docs and possible coding standard tweaks:
This should end in 'templates' per #1913208: [policy] Standardize template preprocess function documentation but still needs to be under 80 characters. Consider adding a separate 'description' line between the summary and 'Default template:' to expand on the summary if necessary.
Per http://drupal.org/node/1354#lists the top level list item needs to end in a colon before starting the sub-list. I don't think this needs three levels of indentation, especially because 'type' is not a variable, it's just what we're using to loop through and could be anything.
I recommend something like this (needs wrapping):
I think we're indenting the contents of the spaceless tag per http://drupal.org/node/1823416#whitespace.
Comment #34
joelpittetCleanup from #33
Comment #35
jenlamptonAwesome review, great cleanup, this looks awesome.
Good job team!
Comment #36
fabianx commented#34: 1898038-34-twig-custom-block.patch queued for re-testing.
Comment #38
star-szrTagging for reroll.
Comment #39
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 #40
widukind commentedComment #41
widukind commentedrerolled.
Comment #42
epersonae2 commented#41: 1898038-41.patch queued for re-testing.
Comment #43
hydra commentedRerolled version is still applying, so for me this seems to be RTBC!
Comment #44
jerdavisStill needs profiling
Comment #44.0
jerdavisrm sand
Comment #45
ezeedub commentedCreate a few custom block types at admin/structure/custom-blocks
Set home page to block/add
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51a40ba394e16&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51a40ba394e16&...
Comment #46
ezeedub commentedsame as #45 with twig_debug turned off this time... :/
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51a43d65a397f&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=51a43d65a397f&...
Comment #47
joelpittetLOL, Ed how did it get slower with Twig debugging turned off and less function calls? I'm going to chalk that into margin of error land, maybe Fabianx can explain?
Nevertheless, thanks for profiling this one:)
Comment #48
fabianx commentedYes, that is within error margin. If we compare the pure function calls:
=> Around 0.6 - 0.8 ms slower should be reachable from just the changed function calls, which would be an overhead of around 0.3%.
So with error margin, this would probably be like 0.3 - 0.5% slower to call the template than to call the theme_ function.
Comment #49
joelpittetOk great. Thanks for your expertise @Fabianx
Comment #50
alexpottCommitted cd4c61e and pushed to 8.x. Thanks!
Comment #51.0
(not verified) commentedadd attribution.