+ All Categories
Home > Technology > Integrating Drupal 8 into Symfony 2

Integrating Drupal 8 into Symfony 2

Date post: 10-May-2015
Category:
Upload: fabrice-bernhard
View: 6,141 times
Download: 0 times
Share this document with a friend
Description:
Drupal 8 is now introducing more and more Symfony2 components into its architecture. This will make it possible to use Symfony2 paradigms when building custom modules in Drupal 8. But what if you want to go further and include a standard Drupal 8 inside a Symfony2 project? This presentation shows how to do it in a step-by-step approach and gives more generic advice on how to wrap php application inside a Symfony2 application.
Popular Tags:
49
THEODO 20/09/201 3 1 Wrapping PHP in Symfony2 Integrating Drupal8 into Symfony2
Transcript
Page 1: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 1

Wrapping PHP in Symfony2Integrating Drupal8 into Symfony2

Page 2: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 2

When Drupal8 started rocking the PHP world

The technical challenges of PHP wrapping

Integrating Drupal8 into Symfony2, step by step

Page 3: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 3

Drupal usage is growing 2x faster than WordpressDrupal’s position in the CMS landscape

• Drupal is used by 2% of the top 1 million websites, according to W3Techs.com

• +21% growth last year!To compare with Joomla: +0% and Wordpress:

+11%

• Acquia expects $68 million revenue in 2013 with +50% growth

Page 4: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 4

Drupal powers many influential websitesDrupal’s position in the CMS landscape

Page 5: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 5

Drupal powers many influential websitesDrupal’s position in the CMS landscape

Page 6: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 6

Drupal 8 is due this year after two years of hard workThe new Drupal version

Page 7: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 7

Drupal 8 is due this year after two years of hard workThe new Drupal version

• 7 core initiatives organized in a Scrum-ish way• Mobile• Multilingual• Layouts• Views in core• HTML5• Web Services• Configuration Management

• The last phase « API completion » started on July 1st

Page 8: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 8

Drupal 8 wants to become a content management platformThe web service core initiative

Page 9: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 9

So Larry started looking for a good Request/Response library to include in the Web Services core initiative…The introduction of the HttpKernel

Page 10: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 10

…and that is when Stof changed the PHP worldHow Drupal chose Symfony2

« And then this French guy Stof spent hours on IRC with me, convincing me step by step how all my problems would be solved by the HttpKernel. I realised afterwards it was nighttime in France »

Page 11: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 11

Since then Symfony2 is taking over Drupal 8Symfony2 components adopted by Drupal 8

Page 12: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 12

Since then Symfony2 is taking over Drupal 8Drufony

Page 13: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 13

16 000 additional contributors to Symfony2!The power of the Drupal community

Page 14: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 14

When Drupal8 started rocking the PHP world

The technical challenges of PHP wrapping

Integrating Drupal8 into Symfony2, step by step

Page 15: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 15

Why is wrapping not as easy as include?Challenges behind PHP wrapping

Page 16: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 16

PHP is designed around « one request <-> one process »Challenges behind PHP wrapping

The consequences of this simple design are obvious:

• Want to output something? echo to STDOUT• Want to end the request? => exit()• Want to share something inside the process? => $GLOBAL• Want to call two classes with the same name? => who needs that?

PHP is everything but Stateless

Page 17: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 17

Catching the output

Page 18: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 18

Catching the exits

Page 19: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 19

Handling globals

Page 20: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 20

Class and function conflictsHistory of PHP applications

• Write a custom autoloader for classes• And for functions…

Page 21: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 21

Handling session already startedHistory of PHP applications

Page 22: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 22

When Drupal8 started rocking the PHP world

The technical challenges of PHP wrapping

Integrating Drupal8 into Symfony2, step by step

Page 23: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 23

A big picture of how a request is handled by Drupal 8Drupal 8 architecture

The start is (almost) like Symfony

Page 24: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 24

A big picture of how a request is handled by Drupal 8Drupal 8 architecture

Authentication

• is handled by AuthenticationSubscriber started by the onKernelRequestAuthenticate event

• Depends on the AuthenticationManager service

• That choses between the Cookie or HTTPBasic provider

• In the end the Cookie provider just wraps the legacy drupal_session_initialize()

Page 25: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 25

A big picture of how a request is handled by Drupal 8Drupal 8 architecture

Page 26: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 26

A big picture of how a request is handled by Drupal 8Drupal 8 architecture

Routing• Is handled by the CMFChainRouter• Which looks first in the DynamicRouter and then the

LegacyUrlMatcher• LegacyUrlMatcher just wraps menu_get_item()

HTMLPageController• Wraps drupal_render_page

Page 27: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 27

A big picture of how a request is handled by Drupal 8Drupal 8 architecture

Page 28: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 28

Let’s start to hack! Integration plan

Goals

• #1: Wrap Drupal in Symfony2

• #2: Access Drupal nodes and session from a Symfony2 controller

Page 29: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 29

Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener

Page 30: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 30

Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener

Page 31: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 31

Routing between Symfony2 and DrupalTheodoDrupal8Bundle\RouterListener

Page 32: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 32

Buffering the kernelTheodoDrupal8Bundle\RouterListener

Page 33: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 33

Cannot redeclare assetic_init()Class loading issues

Page 34: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 34

Cannot redeclare assetic_init()Class loading issues

Page 35: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 35

Cannot redeclare assetic_init()Class loading issues

Page 36: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 36

Symlinks to what Drupal expects to be in web rootAssets and symlinks

Symbolic links to modules, profiles, sites and themes

Symbolic links to the same folders (and just these) in core

Page 37: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 37

Change Drupal settings accordinglyAssets and symlinks

Page 38: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 38

http://sf2drupal/app_dev.php/user works!Routing demo

Symfony’s debug toolbar!

Drupal’s new responsive theme

Page 39: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 39

There is still a bug in the Symfony profiler…RequestDataCollector bug

Page 40: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 40

Corrected in a PULL REQUEST!RequestDataCollector bug

Page 41: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 41

Access every service from core.services.ymlDrupal Service Container

Page 42: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 42

For example: accessing node contentgetNode

Page 43: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 43

Getting the Drupal connected usergetCurrentUser

Page 44: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 44

Integrating Drupal 8 into Symfony2DemoController

Page 45: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 45

Integrating Drupal 8 into Symfony2!DemoController

Node content!

Current user name!

Page 46: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 46

How to do this at homeTheodoDrupal8bundle

https://github.com/theodo/TheodoDrupal8Bundle

Page 47: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 47

Tips to help you continue integratingPHP integration

• Good IDE + Xdebug to follow the code

• Put a breakpoint at error handling functions, to read the error inside the code

• Compare the same functionality/page with and without wrapping

• Other interesting bundle: https://github.com/theodo/TheodoEvolutionSessionBundle

Page 48: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 48

What are the next prioritiesNext steps

• Integration must bring ease of adding custom logic in Symfony controllers => like RogerCMS

• See how Symfony2 can improve Drupal 8 performances…• Session and permission sharing

Page 49: Integrating Drupal 8 into Symfony 2

THEODO20/09/2013 49

Questions [email protected]

@theodowww.theodo.fr

Feedback: https://joind.in/9329


Recommended