Markup Ain't Easy
or
How I Learned to love An
Object-Oriented RenderAPI
Carl Wiedemann • Drupalcon Austin
June 4, 2014 1:0...
So theming is
hard
Theming is hard
because
the render system
is complicated
Things are getting better!
But rendering hasn't
changed much.
The render system
is complicated
because of
implementation
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no t...
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no t...
Instead we have
drupal_render()
“ArrayPI”
How drupal_render() “works.”
1. Create a big array of stuff.
How drupal_render() “works.”
1. Create a big array of stuff.
2. Eat it!
How drupal_render() “works.”
1. Create a big array of stuff.
2. Eat it!
3. Return a string that came from
somewhere.
How drupal_render() “works.”
One of the longest procedural
functions in core.
drupal_render(), _theme()
185 lines, 244 lin...
How drupal_render() “works.”
It's called a lot.
For non-cached single node
up to 8 recurses, 200+ times total
(via xhprof)
The problem with ArrayPI:
“I am not convinced that this
proposed change will give us
performance increase that will
justif...
“array() is dead.”
- 8.x
long live array()!
-drupal_render()
This slide intentionally left blank.
Let's talk conceptuallyLet's talk conceptually
aboutabout
rendering.rendering.
What do we need?What do we need?
What do we need?What do we need?
I. An abstracted, alterable,I. An abstracted, alterable,
consistent model ofconsistent mo...
What do we need?What do we need?
I. An abstracted, alterable,I. An abstracted, alterable,
consistent model ofconsistent mo...
We have arrays!
OBJECTS
Render API principles:
OBJECTS
{{ demo }}
http://github.com/c4rl/renderapi
Render API principles
1. Render arrays move to a
Builder pattern
Object creation is delegated
to a series of steps then fi...
Render API principles
2. Preprocess/process moves to a
Decorator pattern
Behavior added to object
dynamically at runtime w...
Render API principles
3. Building and decoration isn't
invoked until the builder is cast to
a string.
__toString() magic m...
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no t...
The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
because we have no t...
...potentially :)
fixed
This slide also intentionally left blank.
@todo
Questions, feedback, reengage
discussion.
Proof-of-concept in 8.x sandbox,
tests & benchmarking.
Please evaluate this session
https://austin2014.drupal.org/node/2618
Photos
http:/ en.wikipedia.org/wiki/George_Washington_University
http://flickr.com/photos/vanessaberry/4128711965
This wor...
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
Upcoming SlideShare
Loading in …5
×

Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI

819 views

Published on

It's no secret that since the release of Drupal 7 the way that we present markup (a little thing we call the Drupal theme layer) has undergone sweeping and revolutionary changes. Twig! And there was much rejoicing, ringing out from every street corner of the globe, celebrating a long, treacherous, journey filled with chasms of despair and despicable Arrays Of Doom.

But as all great sagas continue Through the Ages, this saga is no exception.

Read more: https://austin2014.drupal.org/session/markup-aint-easy-or-how-i-learned-love-object-oriented-renderapi

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
819
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI

  1. 1. Markup Ain't Easy or How I Learned to love An Object-Oriented RenderAPI Carl Wiedemann • Drupalcon Austin June 4, 2014 1:00PM - 2:00PM Room 15 - Commerce Guys, 4th floor https://austin2014.drupal.org/node/2618
  2. 2. So theming is hard
  3. 3. Theming is hard because the render system is complicated
  4. 4. Things are getting better! But rendering hasn't changed much.
  5. 5. The render system is complicated because of implementation
  6. 6. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" />
  7. 7. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" /> We can't do this
  8. 8. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" /> We can't do this because we have no true API.
  9. 9. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" /> We can't do this because we have no true API. src is in template_preprocess_image() ...which happens after template_preprocess_node() so the node template has no access ...because we want to render things on the fly (which is good) …but arrays aren't smart.
  10. 10. Instead we have drupal_render()
  11. 11. “ArrayPI”
  12. 12. How drupal_render() “works.” 1. Create a big array of stuff.
  13. 13. How drupal_render() “works.” 1. Create a big array of stuff. 2. Eat it!
  14. 14. How drupal_render() “works.” 1. Create a big array of stuff. 2. Eat it! 3. Return a string that came from somewhere.
  15. 15. How drupal_render() “works.” One of the longest procedural functions in core. drupal_render(), _theme() 185 lines, 244 lines
  16. 16. How drupal_render() “works.” It's called a lot. For non-cached single node up to 8 recurses, 200+ times total (via xhprof)
  17. 17. The problem with ArrayPI: “I am not convinced that this proposed change will give us performance increase that will justify the complexity we'll have to introduce.” - jessebeach https://drupal.org/node/2099131
  18. 18. “array() is dead.” - 8.x long live array()! -drupal_render()
  19. 19. This slide intentionally left blank.
  20. 20. Let's talk conceptuallyLet's talk conceptually aboutabout rendering.rendering.
  21. 21. What do we need?What do we need?
  22. 22. What do we need?What do we need? I. An abstracted, alterable,I. An abstracted, alterable, consistent model ofconsistent model of structured content.structured content.
  23. 23. What do we need?What do we need? I. An abstracted, alterable,I. An abstracted, alterable, consistent model ofconsistent model of structured content.structured content. II. A sensible, accessibleII. A sensible, accessible API for this model.API for this model.
  24. 24. We have arrays!
  25. 25. OBJECTS
  26. 26. Render API principles: OBJECTS {{ demo }} http://github.com/c4rl/renderapi
  27. 27. Render API principles 1. Render arrays move to a Builder pattern Object creation is delegated to a series of steps then finally invoked.
  28. 28. Render API principles 2. Preprocess/process moves to a Decorator pattern Behavior added to object dynamically at runtime without affecting other objects of the same class.
  29. 29. Render API principles 3. Building and decoration isn't invoked until the builder is cast to a string. __toString() magic method
  30. 30. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" /> We can't do this because we have no true API. src is in template_preprocess_image() ...which happens after template_preprocess_node() so the node template has no access ...because we want to render things on the fly (which is good) …but arrays aren't smart.
  31. 31. The aspirations of Twig node.html.twig <img src="{{ content.field_image.1.src }}" /> We can't do this because we have no true API. src is in template_preprocess_image() ...which happens after template_preprocess_node() so the node template has no access ...because we want to render things on the fly (which is good) …but arrays aren't smart. FIXED
  32. 32. ...potentially :) fixed
  33. 33. This slide also intentionally left blank.
  34. 34. @todo Questions, feedback, reengage discussion. Proof-of-concept in 8.x sandbox, tests & benchmarking.
  35. 35. Please evaluate this session https://austin2014.drupal.org/node/2618
  36. 36. Photos http:/ en.wikipedia.org/wiki/George_Washington_University http://flickr.com/photos/vanessaberry/4128711965 This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.

×