The Drupal 8 Page Model

Sam Boyer @sdboyer

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

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>
					

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

In Drupal, the "page" is really about governance

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

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

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