You are here

public function WebhookSubscriber::onWebhookReceive in Webhooks 8

Webhook receive event handler.

Parameters

\Drupal\webhooks\Event\ReceiveEvent $event: Response event.

Throws

\Drupal\Core\Entity\EntityStorageException

File

modules/webhook/src/EventSubscriber/WebhookSubscriber.php, line 54

Class

WebhookSubscriber
Webhook event subscriber.

Namespace

Drupal\webhook\EventSubscriber

Code

public function onWebhookReceive(ReceiveEvent $event) {
  $webhook = Webhook::create([
    'title' => $this
      ->t('Webhook @uuid', [
      '@uuid' => $event
        ->getWebhook()
        ->getUuid(),
    ]),
    'headers' => json_encode($event
      ->getWebhook()
      ->getHeaders()),
    'payload' => json_encode($event
      ->getWebhook()
      ->getPayload()),
    'created' => time(),
  ]);
  $webhook
    ->save();
}