Services, Services, Services: Using Services in Drupal custom modules


Services is a stable component of OOP PHP programming and is fundamental to programming in Drupal 8. The underlying architecture is the Symfony dependency injection component represented by the service container. Using services allows us to write code that perform certain tasks. These tasks can be swappable, with an additional feature of changing the logic of existing services. Drupal has a list of services that could be incorporated into a custom module, but we can also create our own services to use in the module. Drush commands can also be wrapped up in a service and used within the custom module.

Using a backdrop of a custom module that was developed to allow users to import a .docx file into a website, convert it into json, import it into nodes, and rollback/remove all content all with one click (well a few clicks), this presentation will portray the power of ‘Services’, both Drupal and Drush services.

Areas to touch on:

Module development
Services Drupal, Drush (core and custom)
Dependency injection
Services, tagged services and plugins

Drupal is a registered trademark of Dries Buytaert.