

They are classes used to encapsulate a specific functionality. In Drupal, services are objects living inside the service container. For every Drupal component, the namespace will always start with \Drupal and the rest will depend on what type of element we're adding the class to, following the pattern described in the official documentation. The namespaces work for package-based autoloading and use the standard PSR-4. In Drupal, every class you create must have a corresponding namespace. Probably the most common trait in Drupal is the StringTranslationTrait, which enables the use of the “t” function to translate strings. Traits - An alternative for reusing code, they allow classes that use them to access certain functions without duplicating the code.They define what methods and properties the class should have. Interfaces - These are base templates implemented by classes.Each class can have use statements at the top and requires other classes, interfaces or traits to provide the service. Classes - They’re groups of methods or properties organized in a file offering a certain functionality.Let’s see in more detail what each one of these elements is: It ultimately provides you with objects that extend other objects by using classes, interfaces and traits. Instead of writing the old procedural code, now we work with classes using Object Oriented Programming (OOP), a programming paradigm that involves objects that interact with each other. Since Drupal 8, the paradigm for writing Drupal modules changed for the better. Read on! OOP: Object-Oriented Programming That being said, here’s an introduction to services, plugins and events in Drupal. After the session, we thought it would be nice to write something about it for those who couldn't attend or are interested in levelling up their Drupal module development skills. It was a great event in which we had a wonderful time discussing plugins, services, events and events subscribers.

Recently, my colleague Kevin Porras and I did a presentation at Drupal Camp Costa Rica.
