The Drupal 8 Page Model



The Drupal 8 Page Model

0 0


d8page


On Github sdboyer / d8page

The Drupal 8 Page Model

Sam Boyer @sdboyer

  • this is an advanced talk - won't make much sense unless you know what a render array is, for example
  • my background

A "page model"?

Not "model" as in MVC

(If anything, more akin to "Controller")

It's how Drupal conceives of and organizes an HTML page

  • think Panels, Context: what are the pieces of my page? why?

The Daddy template: html.tpl.php

<html>
  <head>
    <!-- assorted meta tags go here -->
    <!-- as do link tags -->
    <!-- a title tag -->
    <!-- also, stylesheets and javascript -->
  </head>
  <body>
    <!-- "page top" - not much usually goes here -->

    <!-- "page" - almost everything is here: 
                  blocks and page callback, all together -->

    <!-- "page bottom" - usually very little, 
                         sometimes javascript assets. -->
  </body>
</html>

This is html.tpl.php, or html.html.twig in D8. It is very sparse, but it is the only template that really illustrates our page *model*.

page.tpl.php, which people are more accustomed to seeing, is what populates the 'page' var there in the middle.

The fact that we split them this way points to the first bit of conceptual problem: the "page" is kinda what's within the body tags, but also affects the head.

so, the actual 'page' bit? (bait and switch)

jk, it'd be asinine to list 26 vars and regions

  • But seriously, there's a huge amount that goes in there, and it's at a lot of different levels.
  • On the one hand, there's general utility vars - base path, etc. But there's also navigation - does that always make sense to have in the page scope?
  • Then there's Drupal's real domain objects - nodes, tabs, messages, etc. Some of this is always present, some isn't.
  • The point of the exercise is that this set of data - and the how, why, and where of it - are what really constitute the overall page model.

In Drupal, the "page" is really about governance

Who gets to put stuff on the page, and why?

  • this is scary. it should be. modeling and building the page is a question of best practices, competing priorities, and other non-objective criteria.

The better we answer this question, the saner Drupal sitebuilding is for everyone

Drupal 7

hook_page_build() and hook_page_alter() make everything squishy

drupal_add_css/js(), drupal_get_html_head(), etc. blow up encapsulation

  • emphasize that the build, and kinda also the alter, is what injects uncertainty
  • uncertainty is what prevents us from reporting things accurately in the interface, and from doing meta-operations
  • the caching problem is still sorta solveable, which i'll talk about more of in D8

Drupal 8

HtmlFragment

<?php
class HtmlFragment {
  protected $content;
  protected $title;

  public function getTitle() {}
  public function getContent() {}
}

HtmlPage

<?php
class HtmlPage {
  protected $bodyTop;
  protected $bodyBottom;

  public function getHtmlAttributes() {}
  public function getBodyAttributes() {}
  public function getStatusCode() {}
}

So...haven't actually solved the problem

Just kinda gotten ready to solve it

Princess

...?

Ciao