Code samples used in the presentation: https://github.com/Ozmodiar/Drupal-DIC-Presentation
These are the slides of the presenation I gave at DrupalCamp Ghent 2014 about developing Drupal 7 with Drupal 8 in mind. A session about how we managed to do Drupal development with object-oriented custom modules and Composer and Symfony Container integration. All to provide an easier migration to Drupal 8 later on.
10. Setup
The problems…
• Always re-instantiating
classes
• Not very maintainable
• Not the D8 way
Vanilla Drupal 7
Object Oriented Code
Dependency Injection
11. Setup
Vanilla Drupal 7
Object Oriented Code
Dependency Injection
What have we done?
13. Setup
This is better, but…
• Still not very readable
• Not flexible enough
• More D8 style, but…
• D8 has a better solution
Vanilla Drupal 7
Object Oriented Code
Dependency Injection
Container
14. Vanilla Drupal 7
Setup
Object Oriented Code
Dependency Injection
Container
What have we done?
• Custom module
• Symfony Container
• D8 uses that too!
• Copy paste library
• xautoload module
16. Setup
This is way better but…
• Bad library maintenance
• D8 has a better solution!
Vanilla Drupal 7
Object Oriented Code
Dependency Injection
Container
Dependency Manager
17. Vanilla Drupal 7
Setup
Object Oriented Code
Dependency Injection
Container
Dependency Manager
What have we done?
• Introduced Composer
• Better library
management
• Libraries not in VCS
• Drupal 8 uses that too!
18. Composer
• Package Manager
• Packagist.org or other VCS
• composer.json
• Vendor folder
• Autoloading
21. Achievements
• Easy external libraries
• More Drupal 8 compliant
• Object Oriented
• Module structure
• DI with Symfony Container
• Less steep learning curve for D8 module dev
22. Extra advantages
• Readability
• Maintainability
• Extensibility
• Easy debugging
• Better testing
• We got off the island (in D7!)
23. Points of attention
• Developers need a new mindset
• Work around D7 limitations
• Different code reviews
24. The next level
• Run your own Packagist (or Satis)
• Write your own interfaces to improve code
reviews
• Write modules as libraries with a Drupal
module as adapter
25. More info
Getting started
http://www.saga.be/dic
Extras
http://youtu.be/GF0EWdsPfZ4 (dependency Injection)
https://getcomposer.org
http://symfony.com/doc/current/book/service_container.html
5 business units
IT projects -> custom projects in Drupal for tourist organisations
Online Communication -> websites in Drupal (and other technologies)
Big project
More than a year ago
-
Maintainability: Classname veranderen = overal aanpassen door heel de code
Maintainability: Classname veranderen = overal aanpassen door heel de code
- Put very simple: Box full of references to classes that contain business logic, refered to as “services”.