Skip to main content
Version: 2023.3

Create a Webhook Processor

Extending or replacing existing processors is as easy as it gets.

General

There are two different EventListener registered in services.yml. Each one of them listens to a specific set of events. If one of these events is triggered, the EventListener calls the corresponding WebhookProcessor, which is responsible for executing the webhook.

Event Listeners

ElementEventListener

Handles all events based on elements, e.g. postAdd and postUpdate events for Data Objects, Documents and Assets.

Pimcore\Bundle\DataHubWebhooksBundle\EventListener\ElementEventListener:
tags:
- { name: kernel.event_listener, event: pimcore.dataobject.postAdd, method: processEvent }
- { name: kernel.event_listener, event: pimcore.dataobject.postUpdate, method: processEvent }
- { name: kernel.event_listener, event: pimcore.dataobject.postUpdateFailure, method: processEvent }
- { name: kernel.event_listener, event: pimcore.asset.postAdd, method: processEvent }
- { name: kernel.event_listener, event: pimcore.asset.postUpdate, method: processEvent }
- { name: kernel.event_listener, event: pimcore.asset.postUpdateFailure, method: processEvent }
- { name: kernel.event_listener, event: pimcore.document.postAdd, method: processEvent }
- { name: kernel.event_listener, event: pimcore.document.postUpdate, method: processEvent }
- { name: kernel.event_listener, event: pimcore.document.postUpdateFailure, method: processEvent }
...

WorkflowEventListener

Handles all events based on workflows, e.g. workflow.entered event.

Pimcore\Bundle\DataHubWebhooksBundle\EventListener\WorkflowEventListener:
tags:
- { name: kernel.event_listener, event: workflow.entered, method: processEvent }
- { name: kernel.event_listener, event: workflow.completed, method: processEvent }

Webhook Processor

The webhook processor is responsible for gathering the payload data and sending the request to all subscribers.

Every WebhookProcessor available needs to be based on the WebhookProcessorInterface.

  • AbstractWebhookProcessor: Provides basic functionalities that are shared between all processors.
  • AssetWebhookProcessor: Provides functionalities specific to Assets, such as adding binary data to requests.
  • DataObjectWebhookProcessor: Provides functionalities specific to Data Objects, such as including unpublished objects.
  • DocumentWebhookProcessor: Provides functionalities specific to Documents, such as userModification.
  • WorkflowWebhookProcessor: Provides functionalities specific to workflows, such as transitions and marking.
tip

If you need more configuration options and want to fully customize the payload sent to your subscribers, you can also create your own webhook processor. It must implement the WebhookProcessorInterface.

Each event that is listened to needs a separate entry in services.yml connecting the processor to the event:

pimcore.webhooks.processor.dataobject.postAdd:
class: Pimcore\Bundle\DataHubWebhooksBundle\Processors\DataObjectWebhookProcessor
arguments:
$httpMethod: 'POST'
tags:
- { name: pimcore.datahub.webhooks_event, event: pimcore.dataobject.postAdd}

pimcore.webhooks.processor.dataobject.postUpdate:
class: Pimcore\Bundle\DataHubWebhooksBundle\Processors\DataObjectWebhookProcessor
arguments:
$httpMethod: 'PUT'
tags:
- { name: pimcore.datahub.webhooks_event, event: pimcore.dataobject.postUpdate}

pimcore.webhooks.processor.dataobject.postUpdateFailure:
class: Pimcore\Bundle\DataHubWebhooksBundle\Processors\DataObjectWebhookProcessor
arguments:
$httpMethod: 'PUT'
tags:
- { name: pimcore.datahub.webhooks_event, event: pimcore.dataobject.postUpdateFailure}

pimcore.webhooks.processor.dataobject.postDelete:
class: Pimcore\Bundle\DataHubWebhooksBundle\Processors\DataObjectWebhookProcessor
arguments:
$httpMethod: 'DELETE'
tags:
- { name: pimcore.datahub.webhooks_event, event: pimcore.dataobject.postDelete}

WebhookProcessorInterface

The three following methods need to be used in your php file for implementing the WebhookProcessorInterface:

  • WebhookProcessorInterface::fire() - responsible for executing the actual webhook based on the configuration in the Datahub.

  • WebhookProcessorInterface::matchByEvent() - checks if the current event can be handled by the WebhookProcessor.

  • WebhookProcessorInterface::matchBySchema() - checks if the event and the corresponding object matches the schema in the Datahub configuration (workspaces, types, ...).