Problem/Motivation
Right now, Twig is bootstrapped/configured via the TwigFactory class. This makes almost impossible to cleanly add extensions on Twig or change the loader.
Proposed resolution
The proposed patch :
* removes the factory and replaces it with proper configuration in the container;
* moves all custom filters/node visitors/tags/functions to a new Drupal Twig extension;
* the render function has been renamed to drupal_render to avoid collision with the same function from the Twig bridge in Symfony. AFAIU, this is only used internally and as such, it should not be a problem.
* the loader is now a service (twig.loader.filesystem) and an alias has been made to twig.loader (which is used by the Twig service). This allows for better flexibility (you can add your own loader for instance by replacing the twig.loader service with a Twig_Loader_Chain one that keeps the default filesystem loader and your own).
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | twig_refactoring_5.patch | 10.61 KB | fabpot |
| twig_refactoring.patch | 8.89 KB | fabpot |
Comments
Comment #1
Crell commentedThis makes sense, I think. The registerTwig() method needs a docblock, however.
Comment #2
chx commentedWhile this is very very lovely, calling render drupal_render is going to be somewhat confusing -- but as it's not exposed to the outside world, it's OK. Here's why: render also includes a show() command which
drupal_renderdoesn't.Comment #3
fabpot commentedI don't have any preferences for the
drupal_rendername. Any suggestions?Comment #4
Crell commenteddrender()? render_array()? render_struct()? (I don't have a strong preference, just throwing out ideas.)
Comment #5
fabpot commentedI've renamed
drupal_rendertorender_var, which probably best describes what it does (and it is kind of symmetric with thetwig_render_templatefunction) .I've also added a phpdoc to the
registerTwig()method as requested.Comment #6
fabpot commentedComment #7
chx commentedI like it.
Comment #8
chx commentedMuch more than that: thanks for doing this, it was on the roadmap all along but we never got around to do this properly.
Comment #9
webchickI don't totally know what this is doing, but I figure if it looks good to fabpot and chx, then who am I to argue? :D
Committed and pushed to 8.x. Thanks!
Comment #11
c4rl commentedTagging