PHP code example of akqa-nz / silverstripe-userforms-webhooks
1. Go to this page and download the library: Download akqa-nz/silverstripe-userforms-webhooks library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
akqa-nz / silverstripe-userforms-webhooks example snippets
public function updateResolvedEndpointURL(string &$url, string $environment): void
{
if ($environment === 'dev') {
$url = 'https://webhook.site/debug';
}
}
// On WebhookPayloadBuilder / WebhookDispatcher
public function updateWebhookPayload(array &$payload, SubmittedForm $submittedForm): void
{
$payload['source'] = 'website';
}
// Add or override template variables used in default fields
public function updateWebhookVariables(
array &$variables,
SubmittedForm $submittedForm,
?EditableWebhook $webhook = null
): void {
$variables['Source'] = 'website';
$variables['Created'] = date('c', strtotime($variables['Created']));
}
// On EditableWebhook / WebhookDispatcher
public function updateWebhookHeaders(array &$headers): void
{
$headers['X-Custom'] = 'value';
}
public function updateWebhookRequestOptions(
array &$options,
EditableWebhook $webhook,
SubmittedForm $submittedForm,
array $payload,
array $data
): void {
$options['timeout'] = 10;
}
public function updateSubmittedWebhook(
SubmittedWebhook $result,
EditableWebhook $webhook,
SubmittedForm $submittedForm,
array $payload
): void {
// inspect or mutate the stored result before write
}