General

  eZ Systems Website
  Technical documentation
  Editor documentation

This Documentation contains:
 
Technical documentation:



⚠ WARNING ! This documentation is deprecated !

Please go to the current Technical Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To complete the implementation, we must register our FieldType Field Type with Symfony , by creating a service for it.

Services are by default declared by bundles in Resources/config/services.yml.

Note
titleUsing a dedicated file for the FieldType Field Type services

In order to be closer with to the kernel best practices, we could declare our FieldType Field Type services in a custom fieldtypes.yml file.

 All we have to do is instruct the bundle to actually load this file in addition to services.yml (or instead of services.yml!). This is done in the extension definition file, DependencyInjection/EzSystemsTweetFieldTypeExtension.php, in the load() method.

Inside this file, file, find this line:

Code Block
languagephp
$loader->load('services.yml');

This is where our bundle tells Symfony that when parameters are loaded, services.yml should be loaded from Resources/config/ (defined above). Either replace edit the line, or add a new one with:

Code Block
languagephp
$loader->load('fieldtypes.yml');

 

Like most API components, FieldTypes 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 is added to a registry using the alias argument as its unique identifier (ezstring, ezxmltext, etc.).  Each FieldType Field Type must also inherit from the abstract ezpublish.fieldType service. This ensures that the initialization steps shared by all fieldtypes Field Types are executed.

Here is the service definition for our Tweet type:

 

Code Block
titleResources/config/services.yml
parameters:
    ezsystems.tweetfieldtypebundle.fieldType.eztweet.class: EzSystems\TweetFieldTypeBundle\eZ\Publish\FieldType\Tweet\Type
 
services:
    ezsystems.tweetfieldtypebundle.fieldType.eztweet:
        parent: ezpublish.fieldType
        class: %ezsystems.tweetfieldtypebundle.fieldType.eztweet.class%
        tags:
            - {name: ezpublish.fieldType, alias: eztweet}


We take care of namespacing our fieldtype Field Type with our vendor and bundle name to limit the risk of naming conflicts.