Drupal 8 And Symfony 2 Framework

The next major Drupal release is going to integrate with the wide PHP ecosystem in a big way. Because of adoption of Symfony2 components, developers will have to learn new things. But this integration is also a big deal for Symfony programmers and the PHP community who Drupal developers will contribute to a deeper level.

We wrote about new Drupal 8 features in this article but now we’re going to focus the attention to Drupal and Symfony2 PHP framework integration. The Drupal and Symfony project introduced the partnership in March last year (2012).

Core Symfony2 components

HttpFoundation and HttpKernel

Drupal will be RESTFull and be able to provide its content via web services and be more flexible.

Dependency Injection

Developing the code using dependency injection means that classes are decoupled from each other so that they are unit-testable and reusable. The DI Container provides the infrastructure allowing interaction of these classes.

Routing

The purpose of the routing component is mapping a HTTP request to a set of configuration variables. Module developers will be able to define a module’s routes in a YAML config file.

ClassLoader

ClasLoader loads project classes when they are needed if they follow the interoperability principles and PSR-0 standard. This way developer will not worry much about module_load_include and other dependencies.

EventDispatcher

Observer pattern is used to enable a system-wide plugin system. Drupal’s hook system will still be present until Drupal 9. The EventDispatcher is going to power a lot of core Drupal components.

Validator

With the Validator component Drupal will validate values in a general sense. For example, form submissions or validating entities within Drupal. The Validator uses Doctrine Annotations for its function.

Twig

Twig is a template engine and it is also created by Symfony2 team so it will fit nicely with other Drupal’s Symfony components. Theme creators definitively should pay attention to the Twig template engine.

Translation

The Translation component provides a standard set of tools for working with translation files and translated strings.

Process

This component executes command line commands in sub-processes. Many Drupal’s tasks will use the Process.

Yaml

YAML allows modules to define configuration settings. This module will be an integral part of Drupal’s Configuration Management Initiative (CMI). This step is big improvement compared to Drupal’s previous attempts to standardize the configuration.

3rd party Symfony components

There are other 3rd party components in addition to Symfony components. They are not part of Symfony framework, but they use it, too. Here are a list of them present in D8:

Doctrine

Doctrine is the name for a set of tools for working with databases and data and D8 uses a part of it named Annotations. It provides extra metadata which could be tricky for beginners but later could become useful, e.g. for defining custom data types.

Doctrine’s ORM (Object Relational Mapper) is not used in Drupal 8 for now.

Composer

Composer represents a dependency manager for PHP which purpose is downloading dependencies for a project. This is similar to the Bundler gem for Ruby.

Assetic

This is ab asset management framework that helps in preparation of additional stuff for page download, e.g. JavaScript and CSS files, images etc.

EasyRDF

The EasyRDF is a library for producing and consuming RDF, allowing Drupal 8 to produce metadata in the markup.

Guzzle

Guzzle is a PHP HTTP client which enables D8 to make web requests. Because Drupal will need to work with many different types of web services, this component is vital for this feature.

PHPUnit

Well-known industry standard unit testing is now part of Drupal core ensuring the code works the right way all the time and making development more efficient.

PSR/Log

The PSR/Log provides a logic for common logging interface through an entire application for both Drupal and Symfony components. It is expected that role of the watchdog will take the Monolog.

Symfony2 CMF’s Routing Component

This component extends Symfony’s routing system and adds some additional classes required by Drupal.

You should be aware that the list of components listed in the article could be changed so stay with us and be informed with fresh updates.