Core Symphony Components in Drupal 8
We all know that all web application communications happens using HTTP.
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.
HTTP foundation mainly deals with two trivial objects:
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.
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.
In the above example, a route is created with the path (/path) and is mapped to an ExampleController Object and its exampleContent method.
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.
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.
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.
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.
Helper components in Drupal 8
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.
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.
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.
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:
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.