Service Tags

Same name in other branches
  1. 9 core/core.api.php \service_tag
  2. 8.9.x core/core.api.php \service_tag
  3. 10 core/core.api.php \service_tag

Service tags overview

Some services have tags, which are defined in the service definition. Tags are used to define a group of related services, or to specify some aspect of how the service behaves. Typically, if you tag a service, your service class must also implement a corresponding interface. Some common examples:

Creating a tag for a service does not do anything on its own, but tags can be discovered or queried in a compiler pass when the container is built, and a corresponding action can be taken. See \Drupal\Core\Render\MainContent\MainContentRenderersPass for an example of finding tagged services.

See Services and Dependency Injection Container for information on services and the dependency injection container.

File

core/core.api.php, line 2553


Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.