Presented by Larry Garfield (@Crell)
implements HuggableDo I need to learn Symfony to use Drupal 8?
No!
Organic Groups?
Panels?
Not a thing
functions?
Nope!
(Drupal 8 is like that, too)
PHP, XML, YAML, Annotations
Please pick one!
"The Drupal Way" is stricter than "The Symfony Way"
Drupal is metaprogramming via the UI
Symfony is metaprogramming via YAML
There is only one template per request
No, really!
Twig inheritance
index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
Welcome to Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}
Your application is ready to start working on it at:
{{ base_dir }}/
What's next?
Read Symfony documentation to learn
How to create your first page in Symfony
{% endblock %}
{% block stylesheets %}
{% endblock %}
base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}
{% block stylesheets %}{% endblock %}
</head>
<body>
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
You're supposed to hack core
class AppKernel extends Kernel
{
/**
* {@inheritDoc}
*/
public function __construct($environment, $debug)
{
// Set the default timezone to UTC.
date_default_timezone_set('UTC');
parent::__construct($environment, $debug);
}
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
}
return $bundles;
}
// ...
}
git commitDrupal always uses View event
Symfony discourages it
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
// replace this example code with whatever you need
return $this->render('default/index.html.twig', array(
'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'),
));
}
}
Drupal always wants a render array
$module.routing.yml, or event
(In Drupal 8)
Hooks ~ Listeners
But also tagged services
(modulo template inheritance)
Making the Web a Better Place
Keep tabs on our work at @Palantir