Looking at system.services.yaml, I noticed that some of the services arguments are strings starting with @. They seem to contain a reference to another defined service.

class: Drupal\system\SystemManager
arguments: ['@module_handler', '@database', '@entity.manager'] 

Are those @-arguments only references to other services? Are there any other type of arguments I can use when defining a new service?


Yes, the @ arguments are references to services. From Symfony's Introduction to Parameters:

You can of course also reference services, which looks a bit different in each format. You can configure the behavior if the referenced service does not exist. By default, an exception is thrown when a non-existent service is referenced.


Start the string with @ or @? to reference a service in Yaml.

  • @mailer references the mailer service. If the service does not exists, an exception will be thrown;

  • @?mailer references the mailer service. If the service does not exists, it will be ignored;

You can also use %-wrapped parameters which are slightly different; they can be used to refer parameters or get access to special SYMFONY__ prefixed server environment vars. (See How to Set External Parameters in the Service Container.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.