On Github wimleers / talk-drupal-8-render-pipeline
… 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
Should be familiar to any Symfony developer!
See symfony.com/doc/2.5/components/http_kernel/introduction.html
⬇
Anything is possible!
The application logic!
In Drupal 7: a page callback.
Determines the content of the response.
Return either:
A Response object A render array An object(with associated VIEW event subscriber)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 …
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.
Add main content renderer services to support more formats!
Let's take a closer look at the most interesting part inside step 6!
Fill page.html.twig's regions + render into Response
Trigger the SELECT_PAGE_DISPLAY_VARIANT event Build selected page display variant (Simple, Block, PageManager …) drupal_render() everything!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!
⬇
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”
⬇
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';
<html> <region> <block data-cache-tags="block:search_form"></block> </region> <region> <block data-cache-tags="block:news"> <view data-cache-tags="view:news"></view> </block> <block data-cache-tags="block:main_content"> <node data-cache-tags="node:17"> <field data-cache-tags="user:2"></field> <field data-cache-tags="filter_format:basic_html file:5 file:3"></field> </node> </block> </region> </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!)