class WebhookSubscriber in Webhooks 8
Webhook event subscriber.
Hierarchy
- class \Drupal\webhook\EventSubscriber\WebhookSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of WebhookSubscriber
1 string reference to 'WebhookSubscriber'
- webhook.services.yml in modules/
webhook/ webhook.services.yml - modules/webhook/webhook.services.yml
1 service uses WebhookSubscriber
File
- modules/
webhook/ src/ EventSubscriber/ WebhookSubscriber.php, line 16
Namespace
Drupal\webhook\EventSubscriberView source
class WebhookSubscriber implements EventSubscriberInterface {
use StringTranslationTrait;
/**
* The messenger.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Constructs event subscriber.
*
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger.
*/
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
/**
* Webhook send event handler.
*
* @param \Drupal\webhooks\Event\SendEvent $event
* Response event.
*/
public function onWebhookSend(SendEvent $event) {
}
/**
* Webhook receive event handler.
*
* @param \Drupal\webhooks\Event\ReceiveEvent $event
* Response event.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
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();
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
WebhookEvents::SEND => [
'onWebhookSend',
],
WebhookEvents::RECEIVE => [
'onWebhookReceive',
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WebhookSubscriber:: |
protected | property | The messenger. | |
WebhookSubscriber:: |
public static | function | ||
WebhookSubscriber:: |
public | function | Webhook receive event handler. | |
WebhookSubscriber:: |
public | function | Webhook send event handler. | |
WebhookSubscriber:: |
public | function | Constructs event subscriber. |