Skip to main content

Custom Publishers

It is possible to customize the way in which a component or content is published to the Content API. To do this, you need to add a custom publisher section in the metadata json:

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

and define the custom publisher as follows:

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.