Passa al contenuto principale

Custom Publishers

E' possibile customizzare il modo in cui un componente o un contenuto è pubblicato verso la Content API. Per farlo, occorre aggiungere una sezione custom_publisher nel json dei metadati:

{
"schema_name": "MyComponent",
"cms_config": {
"custom_publisher": "\\namespace\\...\\MyCustomPublisher::myCallback"
}
"fields": [
...
]
}

e definire il custom publisher come segue:

class MyCustomPublisher {
public static function myCallback(object $componentDto, string $componentAssetId, object $metadata) : void {
// extend/change $componentDto as you want
}
}

The $componentDto object is initialized with the default publishing data, and your custom publisher can change it. The custom publisher can remove fields, but not _id and _type, as they are mandatory.

If you can access the CMS source code, you can find an example of custom publisher in the CmsMediaQueryPublisher class.