Symfony2 Meets Drupal 8

by Larry Garfield

@Crell

Druplicon

2% of the Web runs Drupal

Over 1000 Drupal 7 Contributors

Drupal 7 contributor tag cloud

Over 20,000 new Drupal 7 sites every month

Drupal 7 usage stats

Conclusion...

Drupal is awesome!

Time to kick some ass
in Drupal 8

One small problem...

Drupal is an 11 year old, PHP 4-based extensible Slashdot clone originally written by a Belgian college kid.

Drupal was build for a desktop world
Kitten will fix it

Web Services and Context Core Initiative (WSCCI)

WSCCI

The mission...

Drupal needs to evolve, and quickly, from a first-class web CMS into a first-class REST server that includes a first-class web CMS.

Page layout in Drupal 7

Blocks in Drupal 7

Page layout in Drupal 8 (planned)

Blocks in Drupal 8

Why Symfony?

Drupal 8

Drupal 8 block diagram

(That's the plan, anyway)

Symfony + Drupal
Drupal needs to evolve, and quickly, from a first-class web CMS into a first-class REST server that includes a first-class web CMS.
Hey, look, a first-class REST server!

The kernel

Drupal 7 - index.php

/**
 * @file
 * The PHP page that serves all requests on a Drupal installation.
 */

/**
 * Root directory of Drupal installation.
 */
define('DRUPAL_ROOT', getcwd());

require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
    

Drupal 8 - index.php


use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

define('DRUPAL_ROOT', getcwd());

// Bootstrap all of Drupal's legacy subsystems.
// @see Drupal\Core\EventSubscriber\PathSubscriber;
// @see Drupal\Core\EventSubscriber\LegacyRequestSubscriber;
require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);

// @todo Figure out how best to handle the Kernel constructor parameters.
$kernel = new DrupalKernel('prod', FALSE);

$request = Request::createFromGlobals();
$response = $kernel->handle($request)->prepare($request)->send();

$kernel->terminate($request, $response);
    

Routing

Dependency Injection

Transitional state

    function drupal_container(ContainerBuilder $reset = NULL) {
      static $container = NULL;
      if (isset($reset)) {
        $container = $reset;
      }
      elseif (!isset($container)) {
        $container = new ContainerBuilder();
      }
      return $container;
    }
    
      $langcode = drupal_container()->get('language_interface')->langcode;
    

Now we can inject the language as we move other things into the container.

Eventually remove the wrapper function and inject all the things!

EventDispatcher

EventDispatcher

Hooks

Hooks

Benefits

Limitations

Hooks

    function mymodule_node_access($node, $op, $account) {
      if ($op == 'edit'
          && $node->uid == $account->uid
          && $node->created > (REQUEST_TIME - 3600)) {
        return NODE_ACCESS_ALLOW;
      }
      return NODE_ACCESS_IGNORE;
    }
    

        $return = module_invoke_all('node_access', $node, 'update', $account);
      

Hooks in Drupal 8

Prediction (warning, I know better than to gamble):

Twig

Twig Logo

Templating in Drupal 7

Templating in Drupal 7

Benefits

Drawbacks

DrupalCon Denver - March 2012

We must get rid of these
Arrays of Doom.

--Karoly Negyesi

Twig in Drupal 8

Maybe!

Benefits

Drawbacks

We could use a hand!

Replacing NIH with PIE

Considering...

Clean up all the things!

Let's work together

Collaboration

Coordination

We're in UR pull requests, improvin' ur Framework

We're coming upstream

File Streaming

Odds and ends

Why use Drupal, not pure Symfony?

Drupal is not a Framework

Drupal is not a CMS

What is Drupal?

Drupal is a platform that allows you to assemble your own CMS (or other application).

Why Drupal and Symfony?

We like Symfony2, because it's a set of tools that allows you to assemble your own framework.

You will like Drupal 8 because it's a platform that allows you to assemble your own web application.

Entities/Fields

Click together your own data structure

Fields UI

Rules

Click together your own business logic

Rules UI

Views

Click together your own lists and queries

Views UI

Drupal

Click together your own site

A slideshow built with Views A form built with Views

Distributions: Drupal applications in-a-box

http://www.drupal.org/project/distributions

Open Atrium Drupal Commerce Drupal Commerce Drupal Commons

But wait, there's more!

Do you want Drupal 8?

git clone --recursive --branch 8.x
http://git.drupal.org/project/drupal.git

Do you want help Drupal 8?

Drupal Needs You!

#drupal-contribute
Feature freeze - 1st Dec 2012
Code freeze - 1st April 2013
Release ≈ August 2013

Group hug!
Bay Area Drupal Camp (BADCamp)

It's free!

Questions?

http://groups.drupal.org/wscci

Be nice to me on Joind.in!
https://joind.in/talk/view/7211
Stalk me on Twitter!
@Crell