Service dependencies

In the preceding section, we created a form that allows administrators to set a custom salutation message to be shown on the page. This message was stored in a configuration object that we can now load in our HelloWorldSalutation service. So, let's do just that in a two-step process.

First, we will need to alter our service definition to give our service an argument--the Drupal 8 configuration factory (the service responsible for loading config objects). This is how our service definition should look:

 hello_world.salutation:    class: Drupal\hello_world\HelloWorldSalutation    arguments: ['@config.factory']

The addition is the argument's key, which is an array of service names proceeded by @. In this case, config.factory

Get Drupal 8 Module Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.