To complete the implementation, we must register our Field Type with Symfony by creating a service for it.
Services are by default declared by bundles in Resources/config/services.yml
.
Like most API components, Field Types use the Symfony 2 service tag mechanism.
The principle is quite simple: a service can be assigned one or several tags, with specific parameters. When the dependency injection container is compiled into a PHP file, tags are read by CompilerPass
implementations that add extra handling for tagged services. Each service tagged as
ezpublish.fieldType
is added to a registry using the alias argument as its unique identifier (ezstring
, ezxmltext
, etc.). Each Field Type must also inherit from the abstract ezpublish.fieldType service. This ensures that the initialization steps shared by all Field Types are executed.
Here is the service definition for our Tweet type:
We take care of namespacing our Field Type with our vendor and bundle name to limit the risk of naming conflicts.