Symphony2 Components In Drupal 8 : An Integration Every Drupaler Must Know About

Parent Feed: 
  • By : Prince
  • Date :02-04-2018

Symphony is an open source PHP based web application framework. Symphony uses a set of reusable PHP components to build web applications from scratch. Symphony follows MVC architecture. A kernel is the heart of symphony (Its just a class) and symphony extends this class to in its built applications. Drupal 8 uses some of the symphony core components to extend in terms of quality, scalability, performance, and maintenance.

Core Symphony Components in Drupal 8

1.Http Foundation

We all know that all web application communications happens using HTTP.

Drupal SEO Checklist
web communication

In Drupal 8, when a request is sent from the Web client to the server, it is taken to the front controller (index.php), which in turn sends a request to the handler function. The handler function fetches the results and does the required modifications and responds back to the front controller. From the front controller, the response content is sent to the browser and the request is terminated.

Drupal SEO Checklist
code

HTTP foundation mainly deals with two trivial objects:

  • a)Request
  • b)Response

A request gathers request from $_GET, $_POST, $_SERVER and the response object helps in getting page content & other messages. In Drupal 8, the main support here is to create RESTful API's using the request.

2.Routing

Routing is a controller that processes the above-mentioned HTTP request. In Drupal 7, this was handled by hook_menu functions and in the current version (Drupal 8) it is handled in module.routing.yml file.

example.content:
     path: '/path' 
     defaults: 
      _controller: '_ExampleController::exampleContent' 

In the above example, a route is created with the path (/path) and is mapped to an ExampleController Object and its exampleContent method.

Drupal SEO Checklist
routing

3.Event dispatcher

This concept actually means communicating with all the dependent objects before taking an action.

For example, Let us consider an action node deletion (node_delete). On node deletion action, the event dispatcher needs to check whether any comments are included for the node. If yes, then the node has to communicate with the comment system before performing the action.

EventDispatcher:adding listners

In the above example, the comments are the actual listeners and they register themselves to event dispatcher as listeners. After the comment system has accepted deleting all the comments, the node has to perform delete action.

Event Dispatcher: Event

The above action of letting the listeners know that node is going to be deleted is known as dispatching events.

5.HTTPKernal

HTTP Kernel is the core of Drupal 8 and is extended from HTTPKernelInterface. Drupal kernel is the first object created in Drupal 8. It creates the service container, registers all service providers to the kernel, Handles a request to convert it to a response.

4.Dependency Injection

Symphony uses a service container that efficiently manages the services throughout the applications. This is known as Dependency injection.

In Drupal 8 everything is considered as an object. If you want this object to be available through the applications, then we need to register this as a service in service.yml file. The service container is another object that allows us to create and get services that we already been registered for.

$container ->get('service.name');

Helper components in Drupal 8

1.Serializer

It is the process of transforming objects into specific formats. The formats can be JSON, XML etc. This process of translating data structures can be easily stored and formatted. It is heavily used in Drupal 8 REST API's.

2.Validator

Used for validation of form values based on some rules. It creates constraints for form fields of various field types. For example, validation of a form email field requires validation of its constraints email format.

3.YAML

YAML is the markup language commonly used for storing all configuration. YAML in Drupal 8 is present throughout the system (module.info.yml, services.yml, routing.yml) and views configurations export.

4.Drupal console

Drupal 8 has its own console and can be installed using composer. It is mainly used for debugging and creating skeleton codes for easy implementations.

Some of the common Drupal console commands are:

  • generate:form
  • generate:module
  • generate:controller
  • debug:container

5.Twig Template

Twig in Drupal 8 is a replacement for PHP template engine and is a part of the symphony2 framework. Twig template comes with a wider PHP approach and is most logically suited for Drupal 8 theming.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web