edit description

REST API interaction

When REST API is used, conversion needs to be done for Field Type values, settings and validator configurations. These are converted to and from a simple hash format that can be encoded in REST payload (typically XML or JSON). As conversion needs to be done both when transmitting and receiving data through REST, Field Type implements following pairs of methods:

Method Description
toHash() Converts Field Type Value into a plain hash format.
fromHash() Converts the other way around.
fieldSettingsToHash() Converts Field Type settings to a simple hash format.
fieldSettingsFromHash() Converts the other way around.
validatorConfigurationToHash() Converts Field Type validator configuration to a simple hash format.
validatorConfigurationFromHash() Converts the other way around.

Extension points

Some Field Types will require additional processing, for example a Field Type storing a binary file, or one having more complex settings or validator configuration. For this purpose specific implementations of an abstract class eZ\Publish\Core\REST\Common\FieldTypeProcessor are used. This class provides following methods:

Method Description
preProcessValueHash() Performs manipulations on a received value hash, so that it conforms to the format expected by the fromHash() method described above.
postProcessValueHash() Performs manipulations on a outgoing value hash, previously generated by the toHash() method described above.
preProcessFieldSettingsHash() Performs manipulations on a received settings hash, so that it conforms to the format expected by the fieldSettingsFromHash() method described above.
postProcessFieldSettingsHash() Performs manipulations on a outgoing settings hash, previously generated by the fieldSettingsToHash() method described above.
preProcessValidatorConfigurationHash() Performs manipulations on a received validator configuration hash, so that it conforms to the format expected by the validatorConfigurationFromHash() method described above.
postProcessValidatorConfigurationHash() Performs manipulations on a outgoing validator configuration hash, previously generated by the validatorConfigurationToHash() method described above.

Base implementations of these methods simply return the given hash, so you can implement only the methods your Field Type requires. Some Field Types coming with the eZ Platform installation already implement processors and you are encouraged to take a look at them.

For details on registering a Field Type processor, seeĀ Register Field Type.

Read the Docs