… while waiting for this talk to start, please already download
drupal.org/files/d8_render_pipeline.pdf
Thanks! :)
wimleers.com
@wimleers
Senior Software Engineer
Office of the CTO, Acquia
This is a map of Drupal 8!
…with driving instructions!
In this talk, we're going to look at each area on the map.
…and at the end, you should feel like you understand Drupal 8!
Please download the PDF and follow along!
drupal.org/files/d8_render_pipeline.pdf
index.php
The front controller is a well-known design pattern; it is a section of code that all requests served by an application run through.
app.php
Request $request
HttpKernel
(initialize container, settings.php
)$response = HttpKernel::handle($request)
$response->prepare()
$response->send()
HttpKernel::terminate()
Should be familiar to any Symfony developer!
HttpKernel::handle()
HttpKernel
is the ♥ of Symfony & Drupal!See symfony.com/doc/2.5/components/http_kernel/introduction.html
REQUEST
(negotiation + routing)_controller
)CONTROLLER
(last second overriding)Response
: all done! Otherwise…VIEW
(event subscriber must turn it into a Response
)RESPONSE
(last second modifying)kernel.request
kernel.controller
kernel.view
kernel.response
⬇
Anything is possible!
HttpKernel::handle()
The application logic!
In Drupal 7: a page callback.
Determines the content of the response.
Return either:
Response
objectVIEW
event subscriber)Response
: fully control what's sent (bye bye, exit;
)E.g.: a TabularData
object: rendered as a CSV file response, or a HTML table, or a PDF file, or …
E.g.: a LibraryBook
object: rendered as a JSON response, or an image, or …
MainContent ViewSubscriber
View subscriber that handles (only!) render arrays
The render array-to-response arbitrator logic!
Selects & calls a main content renderer (~ negotiated format)
Another view subscriber could turn a "semantic data object" into a render array…
…and then have this view subscriber render it!
E.g.: a TabularData
object: some view subscriber turns it into a
'#type' => 'table'
render array.
The actual render array-to-response logic!
One "main content renderer"-tagged service per format.
Response
html
text/html
ajax
application/vnd.drupal-ajax
dialog
application/vnd.drupal-dialog
modal
application/vnd.drupal-modal
Add main content renderer
services to support more formats!
Let's take a closer look at the most interesting part inside step 6!
page.html.twig
SimplePageVariant
(just main content, no decoration)BlockPageVariant
(main content with blocks around it)Fill page.html.twig
's regions + render into Response
SELECT_PAGE_DISPLAY_VARIANT
eventSimple
, Block
, PageManager
…)drupal_render()
everything!PartiallyDecapitatedPageVariant
which:
localStorage
to render more dynamic/interactive alternatives to Blocks?Significantly improved rendering of render arrays in Drupal 8!
Too much for this talk, but will cover each in one slide:
Drupal 7:
Not in Drupal 8: asset dependencies!
“How to clear all cache items containing node 42?”
⬇
Impossible!
⬇
Cache tags!
// Associate the 'node:42' cache tag with the render array.
$node = Node::load(42);
$build['#cache']['tags'] = $node->getCacheTags();
// Automatically invalidates the 'node:42' cache tag!
$node->save();
See talks “Building really fast websites with Drupal 8” &
“Render caching in Drupal 7 and 8”
Does the representation of the thing I'm rendering vary per permissions, per URL, per interface language, per … something?
⬇
Cache contexts!
(analogous to HTTP's Vary header)
// Associate the 'user.permissions' cache context with the render array.
if (\Drupal::currentUser()->hasPermission('pet llamas')) {
$build['#markup'] = 'How many llamas will you pet today? :)';
}
$build['#cache']['contexts'][] = 'user.permissions';
Just like JavaScript events!
<html>
</html>
X-Drupal-Cache-Tags
header: efficient Varnish purging!
See talk “Render caching in Drupal 7 and 8”
Needs asset dependencies + cache tags/contexts + bubbling!
See talks “Building really fast websites with Drupal 8” &
“Render caching in Drupal 7 and 8”
(Also see my “renderviz: tool visualizing Drupal 8's render tree” project — ping me if you want to help!)
wimleers.com/talk/drupal-8-render-pipeline