Skip to main content

DrupalDrupal 8 Development Mastery (9): Symfony

Published on 20 August, 2017 - 10:59

It is common knowledge that Symfony is now an integral part of Drupal, specifically Drupal 8. But, what, exactly is it? What is it good for? How is it related to Drupal 8 and why was it adopted? What are its benefits and downsides, with respect to developing for Drupal 8? These am hoping to explore in this article.

First, what is Symfony? It is an open source web-application development framework used for building custom web-based PHP applications. The Symfony system is based on a software architecture that is well-tested, trusted and used by major software projects well beyond Drupal, and even the wider PHP communities.

According to the Symfony Book: "Symfony is a collection of over twenty independent libraries that can be used inside any PHP project. These libraries, called the Symfony Components, contain something useful for almost any situation, regardless of how your project is developed."

The Symfony project is structured into a selection of various components that may be used largely, independently.

What Is Symfony Good For?

Now, you may ask, why was Symfony considered good enough to be adopted into Drupal? The simple answer is twofold: First, because Symfony was built using standard and best practice PHP methods and solutions, it will greatly elevates Drupal to a position where it is taken much more seriously by the larger PHP community.

Previously, Drupal had largely done things its own way, oblivious of the wider PHP community: It cooked up its own unique solutions to common challenges, often in a non-standard way, different from the rest. As a result it became difficult or unattractive for other PHP professionals from the wider community to get into Drupal. This in effect starved Drupal from a much beneficial PHP talent pool for a long time. Now, Drupal 8 changes this.

Second, previously, Drupal had deliberately confined itself to the past by doggedly refusing to modernize. It resisted object-orientation and best-practice/standard solutions that modern software solutions advocates. Instead it chose procedural methods and non-standard, custom, Drupal-only solutions. Now, with Drupal 8, it has taken a giant step away from those pasts, and advanced boldly towards modernization.

And adopting the Symfony2 framework was instrumental to Drupal 8’s achievements in these directions.

What Are The Downsides Of Adopting Symfony In Drupal?

The downsides are twofold:

First, the adopting of Symfony means a strict requirement for modern software best practices and standards like Object-Oriented Programming, strict PHP standards like PSRs, etc, when developing for Drupal. This means that it just became harder to learn developing for Drupal. Previously, developing for Drupal was considered hard, now it just got a lot harder.

Second, many long-established Drupal-centric solutions has now been largely replaced with the more standards-compliant Symfony solutions. As a result formally established Drupal developers are being forced to, either abandon their already well-established skills and upgrade to the new direction or risk becoming irrelevant (Shape up or ship out).

But, the two factors I mentioned above are actually opportunities, if you would just but stop being pessimistic, and perhaps lazy, for a moment. When would learning the modern ways of writing software prove to be bad for you? It can only make you better and current, only for the time and effort it will cost you. No pain, no gain, remember?

And, giving up you Drupal-only skills for ones that are relevant in a world beyond Drupal is not a bad thing either. It will make you become more relevant in a world beyond Drupal.

Just accept the fact that change is a constant, and that the world would not stop making progress just because you are reluctant to follow along. So quit complaining about how difficult things has become and let’s get on with mastering developing with Drupal 8. There’s still a lot of grounds to cover.

So, How Is Symfony Being Used In Drupal 8?

The version of Symfony adopted for Drupal 8 is Symfony2. Like I said earlier Symfony is composed of various components that offers distinct functionality you might need to build your web-based application. Most of these components are optional. You may only use what you need. That is exactly what Drupal does.

Drupal leverages some of Symfony’s components to replace some of its own age-long solutions. More specifically, Drupal uses the following Symfony components, grouped into vital and helper components:

Vital Components

  • HttpKernel
  • Routing
  • EventDispatcher
  • DependencyInjection
  • Http Foundation

Helper Components

  • Debug
  • Process
  • Serializer
  • Validator
  • Translation
  • Yaml

Am not going any deeper into what these components means or does in this post, but you are welcome to explore for yourself using the references listed at the end of this post. The only thing I can say here about these components is that they are heavy on all of the topics we touched on in the Technology Stack section of this series: object-orientation; design patterns like Factory Methods, Dependency Injection; standards like PSR-0 and PSR-4; Late Static Binding; etc.

From a high-level perspective, and without getting too technical, I can say that the heart of the new Drupal 8 framework is the HttpKernel and Http Foundation components. This two components has essentially taken over and changed the Drupal core functionality in a revolutionary way.

They sit between the request from your browser and the other Drupal sub-systems like core and contrib modules, themes, and others. The very simple diagram below illustrates all we needed to understand on how Symfony integrates with Drupal at this juncture in our journey. We will dig deeper as we progress along.

Drupal 8 Development Mastery: Symfony

Other components had also, either replaced some of other Drupal-centric solutions, modified others or introduced something entirely new. Most specifically, the Routing components has replaced the Drupal Menu Hook system (hook_menu) as a means of mapping URL path to the functions that generates the output for the referenced page.

Other components of special interests, IMHO includes: EventDispatcher, DependencyInjection and Yaml.

This post just barely scratches the surface about Symfony in Drupal 8. But it is just good enough for our purpose with this series (see the introductory post).


Next: New 3rd Party libraries: Guzzle, EasyRDF, Zend_Feed


Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Ready to launch your business or organization unto the forefront of the digital revolution?

234-81 7608 4053
A digital technology and solutions services provider. The strategic partner of choice for the future digital business leaders.

Get In Touch