This document summarizes a presentation about the challenges of Drupal's rendering system and a proposed object-oriented alternative. The current system uses arrays and complex procedural functions that are difficult to work with. The presentation proposes moving to an object-oriented model using a builder pattern to construct render objects and decorators to add preprocessing/processing in a more accessible and alterable way. This could help address current issues like fields being inaccessible to templates and improve performance. A proof-of-concept implementation was planned to test these ideas.
Markup Ain't Easy or: How I Learned to love An Object-Oriented RenderAPI
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
9. The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
10. The aspirations of Twig
node.html.twig
<img src="{{ content.field_image.1.src }}" />
We can't do this
11. 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.
12. 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.
20. 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
25. 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.
26. 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.
30. Render API principles
1. Render arrays move to a
Builder pattern
Object creation is delegated
to a series of steps then finally
invoked.
31. 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.
32. Render API principles
3. Building and decoration isn't
invoked until the builder is cast to
a string.
__toString() magic method
33. 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.
34. 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