SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
Single Page Apps with
Drupal 7
Chris	
  Tankersley	
  
ZendCon	
  2015	
  
ZendCon	
  2015	
   1	
  
Who Am I
•  PHP	
  Programmer	
  for	
  over	
  10	
  years	
  
•  Drupal	
  developer	
  for	
  5	
  years	
  
•  h>ps://github.com/dragonmantank	
  
ZendCon	
  2015	
   2	
  
What is a Single Page Application?
•  An	
  applicaFon	
  that	
  loads	
  itself	
  in	
  in	
  a	
  single	
  page	
  
ZendCon	
  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	
  
applicaFon	
  in	
  a	
  single	
  page	
  load	
  	
  
ZendCon	
  2015	
   4	
  
Traditional Application Workflow
ZendCon	
  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	
  
This is heavy
ZendCon	
  2015	
   6	
  
No, it’s really heavy
ZendCon	
  2015	
   7	
  
Single Page Application workflow
ZendCon	
  2015	
   8	
  
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	
  
ZendCon	
  2015	
   9	
  
SPA ALL THE THINGS!
ZendCon	
  2015	
   10	
  
ZendCon	
  2015	
   11	
  
It’s not all great
•  Users	
  have	
  to	
  have	
  JS	
  enabled	
  
•  SEO	
  SUUUUUUUUUUUUUUCKS	
  
•  This	
  will	
  probably	
  break	
  navigaFon	
  
•  This	
  will	
  probably	
  break	
  your	
  analyFcs	
  
•  Your	
  host	
  might	
  not	
  support	
  it	
  
ZendCon	
  2015	
   12	
  
Drupal 7 doesn’t support SPAs
ZendCon	
  2015	
   13	
  
… or does it?
ZendCon	
  2015	
   14	
  
It doesn’t out of the box
ZendCon	
  2015	
   15	
  
Why do you want a Single Page
Application?
ZendCon	
  2015	
   16	
  
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	
  
ZendCon	
  2015	
   17	
  
GMail makes sense
ZendCon	
  2015	
   18	
  
h>p://3.bp.blogspot.com/-­‐y96KrBvSbuQ/Tgu5oLmVZyI/AAAAAAAAAKE/EFkwE1ZIic8/s1600/threadlist-­‐large.png	
  
My blog doesn’t
ZendCon	
  2015	
   19	
  
Don’t create an SPA if…
•  You	
  just	
  want	
  to	
  reduce	
  page	
  refreshes	
  
•  You	
  think	
  it	
  sounds	
  cool	
  
ZendCon	
  2015	
   20	
  
tl;dr: Only create an SPA if it makes sense
ZendCon	
  2015	
   21	
  
Parts of a Single Page Application
ZendCon	
  2015	
   22	
  
The knee bone is connected to…
•  Controllers	
  
•  Chunks	
  and	
  Templates	
  
•  RouFng	
  
•  Data	
  
•  Data	
  Transport	
  
ZendCon	
  2015	
   23	
  
Controllers
ZendCon	
  2015	
   24	
  
h>ps://en.wikipedia.org/wiki/Game_controller#/media/File:SNES-­‐Controller.jpg	
  
The logic of our application
ZendCon	
  2015	
   25	
  
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
ZendCon	
  2015	
   26	
  
<?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
ZendCon	
  2015	
   27	
  
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
ZendCon	
  2015	
   28	
  
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	
  
ZendCon	
  2015	
   29	
  
Sample SPA Application
DEMO	
  TIME!	
  
ZendCon	
  2015	
   30	
  
Picking a JavaScript Framework
ZendCon	
  2015	
   31	
  
Backbone
ZendCon	
  2015	
   32	
  
EmberJS
ZendCon	
  2015	
   33	
  
AngularJS
ZendCon	
  2015	
   34	
  
Getting Drupal 7 to work with Single Page
Applications
ZendCon	
  2015	
   35	
  
The Services Module
ZendCon	
  2015	
   36	
  
What does it do?
“A	
  standardized	
  soluFon	
  of	
  integraFng	
  external	
  applicaFons	
  with	
  
Drupal.	
  Service	
  callbacks	
  may	
  be	
  used	
  with	
  mulFple	
  interfaces	
  like	
  
REST,	
  XMLRPC,	
  JSON,	
  JSON-­‐RPC,	
  SOAP,	
  AMF,	
  etc.	
  This	
  allows	
  a	
  Drupal	
  
site	
  to	
  provide	
  web	
  services	
  via	
  mulFple	
  interfaces	
  while	
  using	
  the	
  
same	
  callback	
  code.”	
  
ZendCon	
  2015	
   37	
  
Services does a lot of heavy lifting for you
ZendCon	
  2015	
   38	
  
Stop!
Demo	
  Time!	
  
ZendCon	
  2015	
   39	
  
Getting it into your Drupal site
ZendCon	
  2015	
   40	
  
Use a .html file
•  Really	
  easy	
  to	
  do	
  
•  Doesn’t	
  impact	
  your	
  exisFng	
  site	
  
ZendCon	
  2015	
   41	
  
Add it to a template
•  Start	
  small	
  
ZendCon	
  2015	
   42	
  
Just make a small module
•  Gives	
  you	
  more	
  control	
  
ZendCon	
  2015	
   43	
  
Questions?
ZendCon	
  2015	
   44	
  
Thank You!
h>p://ctankersley.com	
  
chris@ctankersley.com	
  
@dragonmantank	
  
	
  
h>p://joind.in/talk/view/15586	
  
ZendCon	
  2015	
   45	
  

Weitere ähnliche Inhalte

Was ist angesagt?

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Alexander Lisachenko
 
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014Amazon Web Services
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Magento performance & optimisation best practices
Magento performance & optimisation best practicesMagento performance & optimisation best practices
Magento performance & optimisation best practicesPhilippe Humeau
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applicationsEnrico Zimuel
 
JS digest. Decemebr 2017
JS digest. Decemebr 2017JS digest. Decemebr 2017
JS digest. Decemebr 2017ElifTech
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWSAOE
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
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
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesdrupalindia
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Chen Cheng-Wei
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With ContainersHanoi MagentoMeetup
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalPantheon
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on SteroidsSiteGround.com
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Otto Kekäläinen
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Dana Luther
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimizationAlmog Baku
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHPJonathan Klein
 
Magento 2 performance - a benchmark
Magento 2 performance - a benchmarkMagento 2 performance - a benchmark
Magento 2 performance - a benchmarkByte
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Gavin Pickin
 

Was ist angesagt? (20)

Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
 
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
(WEB304) Running and Scaling Magento on AWS | AWS re:Invent 2014
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Magento performance & optimisation best practices
Magento performance & optimisation best practicesMagento performance & optimisation best practices
Magento performance & optimisation best practices
 
How to scale PHP applications
How to scale PHP applicationsHow to scale PHP applications
How to scale PHP applications
 
JS digest. Decemebr 2017
JS digest. Decemebr 2017JS digest. Decemebr 2017
JS digest. Decemebr 2017
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWS
 
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
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
 
Migraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sitesMigraine Drupal - syncing your staging and live sites
Migraine Drupal - syncing your staging and live sites
 
Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
 
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
#3 Hanoi Magento Meetup - Part 2: Scalable Magento Development With Containers
 
Composer Tools & Frameworks for Drupal
Composer Tools & Frameworks for DrupalComposer Tools & Frameworks for Drupal
Composer Tools & Frameworks for Drupal
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
 
Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]Converting Your Dev Environment to a Docker Stack - php[world]
Converting Your Dev Environment to a Docker Stack - php[world]
 
Wordpress optimization
Wordpress optimizationWordpress optimization
Wordpress optimization
 
Northeast PHP - High Performance PHP
Northeast PHP - High Performance PHPNortheast PHP - High Performance PHP
Northeast PHP - High Performance PHP
 
Magento 2 performance - a benchmark
Magento 2 performance - a benchmarkMagento 2 performance - a benchmark
Magento 2 performance - a benchmark
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
 
Npm scripts
Npm scriptsNpm scripts
Npm scripts
 

Ähnlich wie Single page apps with drupal 7

Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Chris Tankersley
 
Developing ASP.NET MVC Applications Quicker With Kendo UI
Developing ASP.NET MVC Applications Quicker With Kendo UIDeveloping ASP.NET MVC Applications Quicker With Kendo UI
Developing ASP.NET MVC Applications Quicker With Kendo UILohith Goudagere Nagaraj
 
Single Page Applications in Drupal
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in DrupalChris Tankersley
 
Application development using Zend Framework
Application development using Zend FrameworkApplication development using Zend Framework
Application development using Zend FrameworkMahmud Ahsan
 
Architeching a php application with interfaces to the ib mi
Architeching a php application with interfaces to the ib miArchiteching a php application with interfaces to the ib mi
Architeching a php application with interfaces to the ib miChelsea Fenton
 
Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An OverviewJalpesh Vadgama
 
Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?varien
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptxssuser35fdf2
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developerEdureka!
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperEdureka!
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...Mark Leusink
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...Mark Roden
 
Griffon for the Enterprise
Griffon for the EnterpriseGriffon for the Enterprise
Griffon for the EnterpriseJames Williams
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsDenis Izmaylov
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...David Amend
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 

Ähnlich wie Single page apps with drupal 7 (20)

Single Page Apps with Drupal 8
Single Page Apps with Drupal 8Single Page Apps with Drupal 8
Single Page Apps with Drupal 8
 
Developing ASP.NET MVC Applications Quicker With Kendo UI
Developing ASP.NET MVC Applications Quicker With Kendo UIDeveloping ASP.NET MVC Applications Quicker With Kendo UI
Developing ASP.NET MVC Applications Quicker With Kendo UI
 
Single Page Applications in Drupal
Single Page Applications in DrupalSingle Page Applications in Drupal
Single Page Applications in Drupal
 
Node azure
Node azureNode azure
Node azure
 
Application development using Zend Framework
Application development using Zend FrameworkApplication development using Zend Framework
Application development using Zend Framework
 
Architeching a php application with interfaces to the ib mi
Architeching a php application with interfaces to the ib miArchiteching a php application with interfaces to the ib mi
Architeching a php application with interfaces to the ib mi
 
Angular Ivy- An Overview
Angular Ivy- An OverviewAngular Ivy- An Overview
Angular Ivy- An Overview
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?Magento's Imagine eCommerce Conference: Do You Queue?
Magento's Imagine eCommerce Conference: Do You Queue?
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 
Day in a life of a node.js developer
Day in a life of a node.js developerDay in a life of a node.js developer
Day in a life of a node.js developer
 
Day In A Life Of A Node.js Developer
Day In A Life Of A Node.js DeveloperDay In A Life Of A Node.js Developer
Day In A Life Of A Node.js Developer
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
Griffon for the Enterprise
Griffon for the EnterpriseGriffon for the Enterprise
Griffon for the Enterprise
 
Nodejs overview
Nodejs overviewNodejs overview
Nodejs overview
 
Performance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React ApplicationsPerformance and Scalability Art of Isomorphic React Applications
Performance and Scalability Art of Isomorphic React Applications
 
Node js
Node jsNode js
Node js
 
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...Client vs Server Templating: Speed up initial load for SPA with Angular as an...
Client vs Server Templating: Speed up initial load for SPA with Angular as an...
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 

Mehr von Chris Tankersley

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersChris Tankersley
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with gitChris 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)
Using PHP Functions! (Not those functions, Google Cloud Functions)Chris Tankersley
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIChris Tankersley
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for DevelopmentChris Tankersley
 
Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Chris Tankersley
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018Chris Tankersley
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About OptimizationChris Tankersley
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Chris Tankersley
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Chris Tankersley
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Chris Tankersley
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Chris Tankersley
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
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 2017Chris Tankersley
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017Chris Tankersley
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPChris Tankersley
 
Coming to Terms with OOP In Drupal - php[world] 2016
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] 2016Chris Tankersley
 
How We Got Here: A Brief History of Open Source
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 SourceChris Tankersley
 

Mehr von Chris Tankersley (20)

Docker is Dead: Long Live Containers
Docker is Dead: Long Live ContainersDocker is Dead: Long Live Containers
Docker is Dead: Long Live Containers
 
Bend time to your will with git
Bend time to your will with gitBend time to your will with git
Bend time to your will with git
 
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)
Using PHP Functions! (Not those functions, Google Cloud Functions)
 
Dead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPIDead Simple APIs with OpenAPI
Dead Simple APIs with OpenAPI
 
Killer Docker Workflows for Development
Killer Docker Workflows for DevelopmentKiller Docker Workflows for Development
Killer Docker Workflows for Development
 
You Got Async in my PHP!
You Got Async in my PHP!You Got Async in my PHP!
You Got Async in my PHP!
 
Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018
 
Docker for Developers
Docker for DevelopersDocker for Developers
Docker for Developers
 
They are Watching You
They are Watching YouThey are Watching You
They are Watching You
 
BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018BASHing at the CLI - Midwest PHP 2018
BASHing at the CLI - Midwest PHP 2018
 
You Were Lied To About Optimization
You Were Lied To About OptimizationYou Were Lied To About Optimization
You Were Lied To About Optimization
 
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - php[world] 2017
 
Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017Docker for PHP Developers - Madison PHP 2017
Docker for PHP Developers - Madison PHP 2017
 
Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017Docker for Developers - php[tek] 2017
Docker for Developers - php[tek] 2017
 
Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017Why Docker? Dayton PHP, April 2017
Why Docker? Dayton PHP, April 2017
 
OOP Is More Then Cars and Dogs - Midwest PHP 2017
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
 
From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017From Docker to Production - SunshinePHP 2017
From Docker to Production - SunshinePHP 2017
 
Docker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHPDocker for Developers - Sunshine PHP
Docker for Developers - Sunshine PHP
 
Coming to Terms with OOP In Drupal - php[world] 2016
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
 
How We Got Here: A Brief History of Open Source
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
 

Kürzlich hochgeladen

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Kürzlich hochgeladen (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

Single page apps with drupal 7

  • 1. Single Page Apps with Drupal 7 Chris  Tankersley   ZendCon  2015   ZendCon  2015   1  
  • 2. Who Am I •  PHP  Programmer  for  over  10  years   •  Drupal  developer  for  5  years   •  h>ps://github.com/dragonmantank   ZendCon  2015   2  
  • 3. What is a Single Page Application? •  An  applicaFon  that  loads  itself  in  in  a  single  page   ZendCon  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   applicaFon  in  a  single  page  load     ZendCon  2015   4  
  • 5. Traditional Application Workflow ZendCon  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. This is heavy ZendCon  2015   6  
  • 7. No, it’s really heavy ZendCon  2015   7  
  • 8. Single Page Application workflow ZendCon  2015   8   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   …  
  • 9. SPAs are great! •  Reduce  server  load   •  More  responsive   •  Separates  the  server  and  the  front  end   •  Make  the  front  end  people  do  all  the  work   ZendCon  2015   9  
  • 10. SPA ALL THE THINGS! ZendCon  2015   10  
  • 12. It’s not all great •  Users  have  to  have  JS  enabled   •  SEO  SUUUUUUUUUUUUUUCKS   •  This  will  probably  break  navigaFon   •  This  will  probably  break  your  analyFcs   •  Your  host  might  not  support  it   ZendCon  2015   12  
  • 13. Drupal 7 doesn’t support SPAs ZendCon  2015   13  
  • 14. … or does it? ZendCon  2015   14  
  • 15. It doesn’t out of the box ZendCon  2015   15  
  • 16. Why do you want a Single Page Application? ZendCon  2015   16  
  • 17. 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   ZendCon  2015   17  
  • 18. GMail makes sense ZendCon  2015   18   h>p://3.bp.blogspot.com/-­‐y96KrBvSbuQ/Tgu5oLmVZyI/AAAAAAAAAKE/EFkwE1ZIic8/s1600/threadlist-­‐large.png  
  • 19. My blog doesn’t ZendCon  2015   19  
  • 20. Don’t create an SPA if… •  You  just  want  to  reduce  page  refreshes   •  You  think  it  sounds  cool   ZendCon  2015   20  
  • 21. tl;dr: Only create an SPA if it makes sense ZendCon  2015   21  
  • 22. Parts of a Single Page Application ZendCon  2015   22  
  • 23. The knee bone is connected to… •  Controllers   •  Chunks  and  Templates   •  RouFng   •  Data   •  Data  Transport   ZendCon  2015   23  
  • 24. Controllers ZendCon  2015   24   h>ps://en.wikipedia.org/wiki/Game_controller#/media/File:SNES-­‐Controller.jpg  
  • 25. The logic of our application ZendCon  2015   25   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);
  • 26. Chunks and Templates ZendCon  2015   26   <?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 ?>
  • 27. Routing ZendCon  2015   27   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; }
  • 28. Data ZendCon  2015   28   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’,
  • 29. Data Transport •  AJAX   •  AJAJ   •  AJAH   ZendCon  2015   29  
  • 30. Sample SPA Application DEMO  TIME!   ZendCon  2015   30  
  • 31. Picking a JavaScript Framework ZendCon  2015   31  
  • 35. Getting Drupal 7 to work with Single Page Applications ZendCon  2015   35  
  • 36. The Services Module ZendCon  2015   36  
  • 37. What does it do? “A  standardized  soluFon  of  integraFng  external  applicaFons  with   Drupal.  Service  callbacks  may  be  used  with  mulFple  interfaces  like   REST,  XMLRPC,  JSON,  JSON-­‐RPC,  SOAP,  AMF,  etc.  This  allows  a  Drupal   site  to  provide  web  services  via  mulFple  interfaces  while  using  the   same  callback  code.”   ZendCon  2015   37  
  • 38. Services does a lot of heavy lifting for you ZendCon  2015   38  
  • 39. Stop! Demo  Time!   ZendCon  2015   39  
  • 40. Getting it into your Drupal site ZendCon  2015   40  
  • 41. Use a .html file •  Really  easy  to  do   •  Doesn’t  impact  your  exisFng  site   ZendCon  2015   41  
  • 42. Add it to a template •  Start  small   ZendCon  2015   42  
  • 43. Just make a small module •  Gives  you  more  control   ZendCon  2015   43  
  • 45. Thank You! h>p://ctankersley.com   chris@ctankersley.com   @dragonmantank     h>p://joind.in/talk/view/15586   ZendCon  2015   45