Single Page Apps with Drupal 8

Chris Tankersley
Chris TankersleyPHP Programmer at Home
Single Page Apps with
Drupal 8
Chris Tankersley
php[world] 2015
php[world] 2015 1
Who Am I
• PHP Programmer for over 10 years
• Drupal developer for 5 years
• Maintainer of Social Media Bar
• Reigning, Defending, PHP Magic the
Gathering Champion
• https://github.com/dragonmantank
php[world] 2015 2
What is a Single Page Application?
• An application that loads itself in in a single page
php[world] 2015 3
What is a Single Page Application?
• Loads all the necessary HTML, CSS, and JS needed in a single page
load
• Loads all the necessary HTML, CSS, and JS needed to bootstrap an
application in a single page load
php[world] 2015 4
Traditional Application Workflow
php[world] 2015 5
Browser Server
User requests a page
Server returns a response
1) Server gets the request
2) Server calls PHP
3) PHP builds the HTML
Browser Server
User requests a page
Server returns a response
1) Server gets the request
2) Server calls PHP
3) PHP builds the HTML
Single Page Application workflow
php[world] 2015 6
Browser Server
User requests a page
Server returns a response
1) Server gets the request
2) Server returns base HTML
Browser requests data
Server returns a response
1) Server gets the request
2) Server calls PHP
3) PHP returns JSON
Browser requests data
Server returns a response
1) Server gets the request
2) Server calls PHP
3) PHP returns JSON
…
SPAs are great!
• Reduce server load
• More responsive
• Separates the server and the front end
• Make the front end people do all the work
php[world] 2015 7
SPA ALL THE THINGS!
php[world] 2015 8
php[world] 2015 9
It’s not all great
• Users have to have JS enabled
• SEO SUUUUUUUUUUUUUUCKS
• This will probably break navigation
• This will probably break your analytics
• Your host might not support it
php[world] 2015 10
Why do you want a Single Page
Application?
php[world] 2015 11
Create an SPA if…
• You want a more desktop-like experience
• A lot of data is coming and going
• You want/have a good API backend
• The interface lends itself to being an SPA
php[world] 2015 12
GMail makes sense
php[world] 2015 13
http://3.bp.blogspot.com/-y96KrBvSbuQ/Tgu5oLmVZyI/AAAAAAAAAKE/EFkwE1ZIic8/s1600/threadlist-large.png
My blog doesn’t
php[world] 2015 14
Don’t create an SPA if…
• You just want to reduce page refreshes
• You think it sounds cool
php[world] 2015 15
tl;dr: Only create an SPA if it makes sense
php[world] 2015 16
Parts of a Single Page Application
php[world] 2015 17
The knee bone is connected to…
• Controllers
• Chunks and Templates
• Routing
• Data
• Data Transport
php[world] 2015 18
Controllers
php[world] 2015 19
https://en.wikipedia.org/wiki/Game_controller#/media/File:SNES-Controller.jpg
The logic of our application
php[world] 2015 20
function node_page_default() {
$select = db_select('node', 'n')
->fields('n', array('nid', 'sticky', 'created'))
->condition('n.promote', 1)
->condition('n.status', 1)
->orderBy('n.sticky', 'DESC')
->orderBy('n.created', 'DESC')
->extend('PagerDefault')
->limit(variable_get('default_nodes_main', 10))
->addTag('node_access');
$nids = $select->execute()->fetchCol();
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
$build = node_view_multiple($nodes);
Chunks and Templates
php[world] 2015 21
<?php print render($page['header']); ?>
<div id="wrapper">
<div id="container" class="clearfix">
<div id="header">
<div id="logo-floater">
<?php if ($logo || $site_title): ?>
<?php if ($title): ?>
<div id="branding"><strong><a href="<?php print $front_page ?>">
<?php if ($logo): ?>
<img src="<?php print $logo ?>" alt="<?php print
$site_name_and_slogan ?>" title="<?php print $site_name_and_slogan ?>" id="logo"
/>
<?php endif; ?>
<?php print $site_html ?>
Routing
php[world] 2015 22
function hook_menu() {
$items['example'] = array(
'title' => 'Example Page',
'page callback' => 'example_page',
'access arguments' => array('access content'),
'type' => MENU_SUGGESTED_ITEM,
);
$items['example/feed'] = array(
'title' => 'Example RSS feed',
'page callback' => 'example_feed',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
Data
php[world] 2015 23
function node_schema() {
$schema['node'] = array(
'description' => 'The base table for nodes.',
'fields' => array(
'nid' => array(
'description' => 'The primary identifier for a node.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
// Defaults to NULL in order to avoid a brief period of potential
// deadlocks on the index.
'vid' => array(
'description' => 'The current {node_revision}.vid version identifier.',
'type' => 'int’,
Data Transport
• AJAX
• AJAJ
• AJAH
php[world] 2015 24
Sample SPA Application
DEMO TIME!
php[world] 2015 25
Picking a JavaScript Framework
php[world] 2015 26
Backbone
php[world] 2015 27
EmberJS
php[world] 2015 28
AngularJS
php[world] 2015 29
Getting Drupal 8 to work with Single Page
Applications
php[world] 2015 30
Turn on the Modules
php[world] 2015 31
Set the Permissions
php[world] 2015 32
Rest UI
php[world] 2015 33
Creating New Endpoints with Views
php[world] 2015 34
Setting Accept Types
php[world] 2015 35
Stop!
Demo Time!
php[world] 2015 36
Notes for working with the REST API
• No more headers. It’s all through ?_format=*
• You have to know all your base routes
• Use hal_json as a format to make finding links easier
php[world] 2015 37
Why HAL?
• Open spec for describing generic REST resources
• Supports XML and JSON
• Exposes useful links to other bits of resources you might need
• http://phlyrestfully.readthedocs.org/en/latest/halprimer.html
php[world] 2015 38
Getting it into your Drupal site
php[world] 2015 39
Use a .html file
• Really easy to do
• Doesn’t impact your existing site
php[world] 2015 40
Add it to a template
• Start small
php[world] 2015 41
Just make a small module
• Gives you more control
php[world] 2015 42
Questions?
php[world] 2015 43
Thank You!
http://ctankersley.com
chris@ctankersley.com
@dragonmantank
https://joind.in/14801
php[world] 2015 44
1 of 44

Recommended

Drupal8 + AngularJS by
Drupal8 + AngularJSDrupal8 + AngularJS
Drupal8 + AngularJSDaniel Kanchev
1.5K views43 slides
Integrating AngularJS with Drupal 7 by
Integrating AngularJS with Drupal 7Integrating AngularJS with Drupal 7
Integrating AngularJS with Drupal 7andrewmriley
7.1K views22 slides
Drupal & AngularJS - DrupalCamp Spain 2014 by
Drupal & AngularJS - DrupalCamp Spain 2014Drupal & AngularJS - DrupalCamp Spain 2014
Drupal & AngularJS - DrupalCamp Spain 2014Juampy NR
1.8K views20 slides
Nuxt.JS Introdruction by
Nuxt.JS IntrodructionNuxt.JS Introdruction
Nuxt.JS IntrodructionDavid Ličen
2.2K views59 slides
In-depth changes to Drupal 8 javascript by
In-depth changes to Drupal 8 javascriptIn-depth changes to Drupal 8 javascript
In-depth changes to Drupal 8 javascriptThéodore Biadala
7.6K views49 slides
Nuxt.js - Introduction by
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - IntroductionSébastien Chopin
4.5K views45 slides

More Related Content

What's hot

Laravel 8 export data as excel file with example by
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleKaty Slemon
193 views42 slides
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API by
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIBrian Hogg
1.8K views30 slides
Backbone.js by
Backbone.jsBackbone.js
Backbone.jsVO Tho
6.7K views31 slides
Modern Applications With Asp.net Core 5 and Vue JS 3 by
Modern Applications With Asp.net Core 5 and Vue JS 3Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3Alexandre Malavasi
315 views16 slides
WordPress as the Backbone(.js) by
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)Beau Lebens
4.9K views50 slides
Packing for the Web with Webpack by
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with WebpackThiago Temple
834 views48 slides

What's hot(20)

Laravel 8 export data as excel file with example by Katy Slemon
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
Katy Slemon193 views
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API by Brian Hogg
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST APIWordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Brian Hogg1.8K views
Backbone.js by VO Tho
Backbone.jsBackbone.js
Backbone.js
VO Tho6.7K views
Modern Applications With Asp.net Core 5 and Vue JS 3 by Alexandre Malavasi
Modern Applications With Asp.net Core 5 and Vue JS 3Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3
Alexandre Malavasi315 views
WordPress as the Backbone(.js) by Beau Lebens
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
Beau Lebens4.9K views
Packing for the Web with Webpack by Thiago Temple
Packing for the Web with WebpackPacking for the Web with Webpack
Packing for the Web with Webpack
Thiago Temple834 views
Here Be Dragons - Debugging WordPress by Rami Sayar
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
Rami Sayar2K views
BackboneJS Training - Giving Backbone to your applications by Joseph Khan
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
Joseph Khan786 views
BackboneJS and friends by Scott Cowan
BackboneJS and friendsBackboneJS and friends
BackboneJS and friends
Scott Cowan855 views
Understanding backbonejs by Nick Lee
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee2.6K views
Put a little Backbone in your WordPress by adamsilverstein
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
adamsilverstein2.5K views
Packing it all: JavaScript module bundling from 2000 to now by Derek Willian Stavis
Packing it all: JavaScript module bundling from 2000 to nowPacking it all: JavaScript module bundling from 2000 to now
Packing it all: JavaScript module bundling from 2000 to now
AngularJS Deep Dives (NYC GDG Apr 2013) by Nitya Narasimhan
AngularJS Deep Dives (NYC GDG Apr 2013)AngularJS Deep Dives (NYC GDG Apr 2013)
AngularJS Deep Dives (NYC GDG Apr 2013)
Nitya Narasimhan108.8K views
Node.js & Twitter Bootstrap Crash Course by Aaron Silverman
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
Aaron Silverman28.7K views
React basic by Yoav Amit, Wix by Chen Lerner
React basic by Yoav Amit, Wix React basic by Yoav Amit, Wix
React basic by Yoav Amit, Wix
Chen Lerner477 views
Unobtrusive JavaScript by Vitaly Baum
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
Vitaly Baum660 views

Similar to Single Page Apps with Drupal 8

Single page apps with drupal 7 by
Single page apps with drupal 7Single page apps with drupal 7
Single page apps with drupal 7Chris Tankersley
886 views45 slides
Single Page Applications in Drupal by
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in DrupalChris Tankersley
1.3K views45 slides
PHP on Windows and on Azure by
PHP on Windows and on AzurePHP on Windows and on Azure
PHP on Windows and on AzureMaarten Balliauw
2.4K views142 slides
PHP on Windows by
PHP on WindowsPHP on Windows
PHP on Windowsguest60c7659
968 views44 slides
PHP on Windows by
PHP on WindowsPHP on Windows
PHP on WindowsMaarten Balliauw
1.2K views44 slides
SPTechCon 2014 How to develop and debug client side code in SharePoint by
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePointMark Rackley
3.1K views35 slides

Similar to Single Page Apps with Drupal 8(20)

Single Page Applications in Drupal by Chris Tankersley
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in Drupal
Chris Tankersley1.3K views
SPTechCon 2014 How to develop and debug client side code in SharePoint by Mark Rackley
SPTechCon 2014 How to develop and debug client side code in SharePointSPTechCon 2014 How to develop and debug client side code in SharePoint
SPTechCon 2014 How to develop and debug client side code in SharePoint
Mark Rackley3.1K views
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN... by Fwdays
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Maciej Treder "Server-side rendering with Angular—be faster and more SEO, CDN...
Fwdays946 views
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct... by Sébastien Levert
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
Streamlining Your Applications with Web Frameworks by guestf7bc30
Streamlining Your Applications with Web FrameworksStreamlining Your Applications with Web Frameworks
Streamlining Your Applications with Web Frameworks
guestf7bc301.2K views
Max Voloshin - "Organization of frontend development for products with micros... by IT Event
Max Voloshin - "Organization of frontend development for products with micros...Max Voloshin - "Organization of frontend development for products with micros...
Max Voloshin - "Organization of frontend development for products with micros...
IT Event291 views
Web Application Introduction by shaojung
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung918 views
Web Application Introduction by shaojung
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung1.4K views
Web Application Introduction by shaojung
Web Application  IntroductionWeb Application  Introduction
Web Application Introduction
shaojung4.9K views
Automating your php infrastructure with the zend server api by Yonni Mendes
Automating your php infrastructure with the zend server apiAutomating your php infrastructure with the zend server api
Automating your php infrastructure with the zend server api
Yonni Mendes1K views
How and why we evolved a legacy Java web application to Scala... and we are s... by Katia Aresti
How and why we evolved a legacy Java web application to Scala... and we are s...How and why we evolved a legacy Java web application to Scala... and we are s...
How and why we evolved a legacy Java web application to Scala... and we are s...
Katia Aresti1.3K views
Wordcamp Toronto Presentation by Roy Sivan
Wordcamp Toronto PresentationWordcamp Toronto Presentation
Wordcamp Toronto Presentation
Roy Sivan942 views
WordPress and Client Side Web Applications WCTO by Roy Sivan
WordPress and Client Side Web Applications WCTOWordPress and Client Side Web Applications WCTO
WordPress and Client Side Web Applications WCTO
Roy Sivan1K views
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions by Sébastien Levert
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions

More from Chris Tankersley

Docker is Dead: Long Live Containers by
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersChris Tankersley
53 views52 slides
Bend time to your will with git by
Bend time to your will with gitBend time to your will with git
Bend time to your will with gitChris Tankersley
194 views73 slides
Using PHP Functions! (Not those functions, Google Cloud Functions) by
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
177 views72 slides
Dead Simple APIs with OpenAPI by
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIChris Tankersley
311 views63 slides
Killer Docker Workflows for Development by
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
159 views64 slides
You Got Async in my PHP! by
You Got Async in my PHP!You Got Async in my PHP!
You Got Async in my PHP!Chris Tankersley
164 views140 slides

More from Chris Tankersley(20)

Using PHP Functions! (Not those functions, Google Cloud Functions) by Chris Tankersley
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
Chris Tankersley177 views
Killer Docker Workflows for Development by Chris Tankersley
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
Chris Tankersley159 views
Docker for Developers - PHP Detroit 2018 by Chris Tankersley
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018
Chris Tankersley865 views
BASHing at the CLI - Midwest PHP 2018 by Chris Tankersley
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018
Chris Tankersley363 views
Docker for PHP Developers - php[world] 2017 by Chris Tankersley
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017
Chris Tankersley821 views
Docker for PHP Developers - Madison PHP 2017 by Chris Tankersley
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017
Chris Tankersley1.7K views
Docker for Developers - php[tek] 2017 by Chris Tankersley
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
Chris Tankersley1.1K views
OOP Is More Then Cars and Dogs - Midwest PHP 2017 by Chris Tankersley
OOP Is More Then Cars and Dogs - Midwest PHP 2017OOP Is More Then Cars and Dogs - Midwest PHP 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
Chris Tankersley608 views
From Docker to Production - SunshinePHP 2017 by Chris Tankersley
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
Chris Tankersley853 views
Docker for Developers - Sunshine PHP by Chris Tankersley
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
Chris Tankersley812 views
Coming to Terms with OOP In Drupal - php[world] 2016 by Chris Tankersley
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
Chris Tankersley387 views
How We Got Here: A Brief History of Open Source by Chris Tankersley
How We Got Here: A Brief History of Open SourceHow We Got Here: A Brief History of Open Source
How We Got Here: A Brief History of Open Source
Chris Tankersley382 views

Recently uploaded

Cencora Executive Symposium by
Cencora Executive SymposiumCencora Executive Symposium
Cencora Executive Symposiummarketingcommunicati21
139 views14 slides
Data Integrity for Banking and Financial Services by
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial ServicesPrecisely
78 views26 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
179 views7 slides
"Surviving highload with Node.js", Andrii Shumada by
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada Fwdays
53 views29 slides
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITShapeBlue
166 views8 slides
Network Source of Truth and Infrastructure as Code revisited by
Network Source of Truth and Infrastructure as Code revisitedNetwork Source of Truth and Infrastructure as Code revisited
Network Source of Truth and Infrastructure as Code revisitedNetwork Automation Forum
52 views45 slides

Recently uploaded(20)

Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely78 views
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue by ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue179 views
"Surviving highload with Node.js", Andrii Shumada by Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT by ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue197 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue253 views
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue210 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc160 views
The Power of Heat Decarbonisation Plans in the Built Environment by IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... by ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu365 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... by ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue158 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash153 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson156 views

Single Page Apps with Drupal 8

  • 1. Single Page Apps with Drupal 8 Chris Tankersley php[world] 2015 php[world] 2015 1
  • 2. Who Am I • PHP Programmer for over 10 years • Drupal developer for 5 years • Maintainer of Social Media Bar • Reigning, Defending, PHP Magic the Gathering Champion • https://github.com/dragonmantank php[world] 2015 2
  • 3. What is a Single Page Application? • An application that loads itself in in a single page php[world] 2015 3
  • 4. What is a Single Page Application? • Loads all the necessary HTML, CSS, and JS needed in a single page load • Loads all the necessary HTML, CSS, and JS needed to bootstrap an application in a single page load php[world] 2015 4
  • 5. Traditional Application Workflow php[world] 2015 5 Browser Server User requests a page Server returns a response 1) Server gets the request 2) Server calls PHP 3) PHP builds the HTML Browser Server User requests a page Server returns a response 1) Server gets the request 2) Server calls PHP 3) PHP builds the HTML
  • 6. Single Page Application workflow php[world] 2015 6 Browser Server User requests a page Server returns a response 1) Server gets the request 2) Server returns base HTML Browser requests data Server returns a response 1) Server gets the request 2) Server calls PHP 3) PHP returns JSON Browser requests data Server returns a response 1) Server gets the request 2) Server calls PHP 3) PHP returns JSON …
  • 7. SPAs are great! • Reduce server load • More responsive • Separates the server and the front end • Make the front end people do all the work php[world] 2015 7
  • 8. SPA ALL THE THINGS! php[world] 2015 8
  • 10. It’s not all great • Users have to have JS enabled • SEO SUUUUUUUUUUUUUUCKS • This will probably break navigation • This will probably break your analytics • Your host might not support it php[world] 2015 10
  • 11. Why do you want a Single Page Application? php[world] 2015 11
  • 12. Create an SPA if… • You want a more desktop-like experience • A lot of data is coming and going • You want/have a good API backend • The interface lends itself to being an SPA php[world] 2015 12
  • 13. GMail makes sense php[world] 2015 13 http://3.bp.blogspot.com/-y96KrBvSbuQ/Tgu5oLmVZyI/AAAAAAAAAKE/EFkwE1ZIic8/s1600/threadlist-large.png
  • 15. Don’t create an SPA if… • You just want to reduce page refreshes • You think it sounds cool php[world] 2015 15
  • 16. tl;dr: Only create an SPA if it makes sense php[world] 2015 16
  • 17. Parts of a Single Page Application php[world] 2015 17
  • 18. The knee bone is connected to… • Controllers • Chunks and Templates • Routing • Data • Data Transport php[world] 2015 18
  • 20. The logic of our application php[world] 2015 20 function node_page_default() { $select = db_select('node', 'n') ->fields('n', array('nid', 'sticky', 'created')) ->condition('n.promote', 1) ->condition('n.status', 1) ->orderBy('n.sticky', 'DESC') ->orderBy('n.created', 'DESC') ->extend('PagerDefault') ->limit(variable_get('default_nodes_main', 10)) ->addTag('node_access'); $nids = $select->execute()->fetchCol(); if (!empty($nids)) { $nodes = node_load_multiple($nids); $build = node_view_multiple($nodes);
  • 21. Chunks and Templates php[world] 2015 21 <?php print render($page['header']); ?> <div id="wrapper"> <div id="container" class="clearfix"> <div id="header"> <div id="logo-floater"> <?php if ($logo || $site_title): ?> <?php if ($title): ?> <div id="branding"><strong><a href="<?php print $front_page ?>"> <?php if ($logo): ?> <img src="<?php print $logo ?>" alt="<?php print $site_name_and_slogan ?>" title="<?php print $site_name_and_slogan ?>" id="logo" /> <?php endif; ?> <?php print $site_html ?>
  • 22. Routing php[world] 2015 22 function hook_menu() { $items['example'] = array( 'title' => 'Example Page', 'page callback' => 'example_page', 'access arguments' => array('access content'), 'type' => MENU_SUGGESTED_ITEM, ); $items['example/feed'] = array( 'title' => 'Example RSS feed', 'page callback' => 'example_feed', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); return $items; }
  • 23. Data php[world] 2015 23 function node_schema() { $schema['node'] = array( 'description' => 'The base table for nodes.', 'fields' => array( 'nid' => array( 'description' => 'The primary identifier for a node.', 'type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, ), // Defaults to NULL in order to avoid a brief period of potential // deadlocks on the index. 'vid' => array( 'description' => 'The current {node_revision}.vid version identifier.', 'type' => 'int’,
  • 24. Data Transport • AJAX • AJAJ • AJAH php[world] 2015 24
  • 25. Sample SPA Application DEMO TIME! php[world] 2015 25
  • 26. Picking a JavaScript Framework php[world] 2015 26
  • 30. Getting Drupal 8 to work with Single Page Applications php[world] 2015 30
  • 31. Turn on the Modules php[world] 2015 31
  • 34. Creating New Endpoints with Views php[world] 2015 34
  • 37. Notes for working with the REST API • No more headers. It’s all through ?_format=* • You have to know all your base routes • Use hal_json as a format to make finding links easier php[world] 2015 37
  • 38. Why HAL? • Open spec for describing generic REST resources • Supports XML and JSON • Exposes useful links to other bits of resources you might need • http://phlyrestfully.readthedocs.org/en/latest/halprimer.html php[world] 2015 38
  • 39. Getting it into your Drupal site php[world] 2015 39
  • 40. Use a .html file • Really easy to do • Doesn’t impact your existing site php[world] 2015 40
  • 41. Add it to a template • Start small php[world] 2015 41
  • 42. Just make a small module • Gives you more control php[world] 2015 42