Subscribers 

A subscriber is a class that listens to one or more events during the serialization or deserialization process. These events can include pre-serialization, post-serialization, pre-deserialization, and post-deserialization. Subscribers are used to customize the serialization/deserialization process. For example, you might use a subscriber to change the serialized representation of certain types of objects, or to perform some custom logic before an object is serialized.

Subscribers are registered in $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'] . Each of them has to implement \JMS\Serializer\EventDispatcher\EventSubscriberInterface. To add your own subscriber add it in ext_localconf.php of your extension:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'][] = \Vendor\Extension\Serializer\Subscriber\MySubscriber::class;
Copied!

Here is a list of built-in T3api subscribers.

AbstractEntitySubscriber 

This subscriber listens to the POST_SERIALIZE and PRE_DESERIALIZE events. In the case of the POST_SERIALIZE event, it adds additional properties (defined in $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['forceEntityProperties'] , by default uid) and IRI (@id) to the serialized object if the object is an instance of AbstractDomainObject. IRI is added only if the class is an API resource with an item operation. In the case of the PRE_DESERIALIZE event, it changes the type of nested entities to a custom one to enable data handling with a serializer handler (so related records can be passed in payload as uid or as an object).

CacheTagSubscriber 

This subscriber listens to the POST_SERIALIZE event. For every serialized AbstractDomainObject it collects cache tags <table> and <table>_<uid> (e.g. tx_news_domain_model_news_1). Tags are used by response cache to invalidate cached responses when a record is changed. Tags are collected only while response cache is collecting (otherwise the subscriber does nothing).

CurrentFeUserSubscriber 

This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events. On PRE_SERIALIZE, it replaces CurrentFeUserHandler::TYPE with the configured frontend user model class. On PRE_DESERIALIZE, it makes sure that CurrentFeUserHandler is called for every property of this type, so the currently logged in frontend user is attached to the incoming data. Serialized names defined in annotations and YAML metadata are respected, and serialization groups and property exclusions determine which properties are processed. Look for more info at current user assignment use case.

FileReferenceSubscriber 

This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events. In both cases, if the type is a subclass of FileReference or Folder (on deserialization also File and its subclasses) and it is nested in another object, it changes the type to a custom one to enable data handling with FileReferenceHandler (see FileReference).

FileTokenSubscriber 

This subscriber listens to the POST_SERIALIZE event. It adds fileToken to files (sys_file) which can be referenced in the next request, see File token.

GenerateMetadataSubscriber 

This subscriber listens to the PRE_SERIALIZE and PRE_DESERIALIZE events. In both cases, it generates YAML serializer metadata (merged from annotations and YAML metadata) and caches it in var/cache/code/t3api/jms-metadir. Data from var/cache/code/t3api/jms-metadir is later used to serialize/deserialize by JMS serializer.

ResourceTypeSubscriber 

This subscriber listens to the POST_SERIALIZE event. It adds the resource type (@type) to the serialized object if the object is an instance of AbstractDomainObject. Value is the fully qualified class name, e.g. SourceBroker\\T3apinews\\Domain\\Model\\News . Adding @type is not activated by default as it can take a lot of space in the response. To activate it add in your local extension ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3api']['serializerSubscribers'][] = \SourceBroker\T3api\Serializer\Subscriber\ResourceTypeSubscriber::class;
Copied!

ThrowableSubscriber 

This subscriber listens to the POST_SERIALIZE event. If the object is an instance of Throwable, it adds hydra:description (exception message) and - in Development application context only - hydra:debug (stack trace) to the serialized object.

Unexpected exceptions (not implementing SourceBroker\T3api\Exception\ExceptionInterface) are logged with an event ID and result in HTTP 500. Outside of Development application context the response contains a generic SourceBroker\T3api\Exception\InternalServerErrorException with this event ID instead of the original exception, so its message is not returned to the client. Use the event ID to find the original exception in the TYPO3 log.