Reliability, Power and Modularity : Drupal 8 and Symfony 2

Wednesday 14 February 2018

To enhance the power and the viability of Drupal, a catalyst is often needed : here, we will use Symfony 2. The main difference between Drupal 8 and its own previous releases is the ability to integrate the Symfony Framework. It allows devs to create better and bigger apps that fullfil sprecific enterprise needs.

Symfony and Drupal 8

Why do we integrate Symfony 2 into Drupal 8 ?

Drupal was already a flexible and extensible CMS thanks to more than 6000 complementary modules. However, the Drupal 8 release made a huge difference because of the Symfony’s 2 components integration and the setup of good development practices that were missed until today such as oriented object development, unit testing that makes possible to verify that each function is well executed, the HTTPS compliance, twig as a template engine that makes the theming easier and also an API Rest.

The integration of Symfony’s 2 components in Drupal 8 has numerous pros. Here’s a non exhaustive list :

  • By using Symfony’s 2 components, Drupal is becoming entirely object oriented which makes the dev process easier when more powerful web plateforms are developed.
  • Symfony includes a more powerful and structurated core than Drupal’s one, it allows a better accessibility and maintenance. The framework makes possible to only call for necessary ressources for each page loading. That lowers the ressources calls needed to display a website created using Drupal 8.
  • The association of Symfony’s PHP libraries to Drupal modules allows to setup a caching system managed by blocks : the managing of dynamic content is clearly enhanced.

To check out the Symfony’s components and functions integrated into Drupal 8, read below!

Symfony’s components

  • HttpFoundation and HttpKernel : HttpFoundation is aimed to create an object oriented layer that replaces PHP global variables and functions. Concerning HttpKernel, it provides a way to convert requests to responses by using the EventDispatcher component that makes possible to build flexible and powerful HTTP Frameworks.
  • Routing : It allows to associate a HTTP request to a set of configuration variables that can be used in recall PHP functions. It simplifies the setup of easily indexable URLs without having to use a .htaccess file.
  • Event Dispatcher : This component makes the application’s components communicate with each other by dispatching and listening to them.
  • YAML : YAML is an interesting format regarding configurations. As a non tagging langage, it’s easily understable for humans. This component analyses YAML strings in order to convert them to PHP tables. It allows also the conversion of PHP tables into YAML strings. We notice that YAML can be used instead of using XML or JSON files.
  • Process : It executes command lines in sub-processes in order to limit execution time of a process.
  • Serializer : It allows PHP objects conversion into a specific format (XML, JSON, YAML…) and vice versa.
  • Validator : This one provides mecanisms used to inspect any PHP variable. This component aims to simplify constains callbacks. That’s useful when a data validation is needed. Moreover, it enhances the images validations.
  • Translation : It provides necessary tools to create rendering systems (templates). Used in Drupal 8, this component allows to write a code that makes classes reused and tested one by one.
  • Dependency injection : It centralizes the way objects are built in an application. Moreover, it empowers the modularity of Drupal thanks to a dynamic dependancies management of classes.
  • ClassLoader : This component loads automatically project’s classes if they’re PHP conventions compliant.