{% extends '_layouts/cp' %} {% set selectedSubnavItem = 'manage' %} {% set fullPageForm = true %} {% set showFilters = allFilters|filter(f => f.show)|length != 0 %} {% import '_includes/forms' as forms %} {% block actionButton %}
{% if webhook.id %} {% endif %}
{% endblock %} {% block content %} {% if webhook.id %}{% endif %} {{ forms.textField({ first: true, label: 'Name'|t('webhooks'), required: true, instructions: 'What the webhook will be called within the Control Panel.'|t('webhooks'), id: 'name', name: 'name', value: webhook.name, errors: webhook.getErrors('name') }) }} {% set classInput = include('webhooks/_manage/class-autosuggest', { id: 'class', name: 'class', class: 'code ltr', placeholder: 'craft\\elements\\Entry', value: webhook.class, errors: webhook.getErrors('class') }, with_context = false) %} {{ forms.field({ label: 'Sender Class'|t('webhooks'), required: true, instructions: 'The class name the sender must be an instance of.'|t('webhooks'), errors: webhook.getErrors('class') }, classInput) }} {% set eventInput = include('webhooks/_manage/event-autosuggest', { id: 'event', name: 'event', class: 'code ltr', placeholder: 'afterSave', value: webhook.event, errors: webhook.getErrors('event') }, with_context = false) %} {{ forms.field({ label: 'Event Name'|t('webhooks'), required: true, instructions: 'The name of the event that must be triggered.'|t('webhooks'), errors: webhook.getErrors('event') }, eventInput) }} {% set filtersInput %}
{% for filter in allFilters %} {% tag 'tr' with { class: not filter.show ? 'hidden' : false, data: { class: filter.class, excludes: filter.excludes ?? [], }, } %} {% endtag %} {% endfor %}
{% endset %} {{ forms.field({ id: 'filters', label: 'Event Filters'|t('webhooks'), instructions: 'Checks that can determine whether a webhook should be executed.'|t('webhooks') }, filtersInput) }} {% set urlInput %}
{{ forms.select({ id: 'method', name: 'method', options: { 'get': 'GET', 'post': 'POST', 'put': 'PUT', }, value: webhook.method, toggle: true, targetPrefix: 'method-settings--' }) }}
{{ forms.text({ id: 'url', name: 'url', placeholder: 'https://', value: webhook.url }) }}
{% endset %} {{ forms.textField({ label: 'Debounce Key Format'|t('webhooks'), instructions: 'Template that defines the webhook’s “debounce key” format. If two webhooks generate the same debounce key, only the latter will be sent.'|t('webhooks') ~ ' ' ~ 'Can be set to an environment variable (`$VARIABLE_NAME`) or Twig code.'|t('webhooks'), id: 'debounce-key-format', class: 'code', name: 'debounceKeyFormat', value: webhook.debounceKeyFormat, errors: webhook.getErrors('debounceKeyFormat') }) }} {{ forms.field({ label: 'Request Method & URL'|t('webhooks'), required: true, instructions: 'The request method and URL that the webhook should send.'|t('webhooks') ~ ' ' ~ 'Can be set to an environment variable (`$VARIABLE_NAME`) or Twig code.'|t('webhooks'), id: 'url', errors: webhook.getErrors('url') }, urlInput) }} {{ forms.editableTableField({ id: 'headers', name: 'headers', label: 'Custom Headers'|t('webhooks'), instructions: 'Any custom headers that should be sent.'|t('webhooks'), cols: { name: { heading: 'Name'|t('webhooks'), type: 'singleline', code: true, placeholder: 'X-Foo-Bar', }, value: { heading: 'Value'|t('webhooks'), info: 'Can be set to an environment variable (`$VARIABLE_NAME`) or Twig code.'|t('webhooks'), type: 'multiline', code: true, placeholder: '{{ event.sender.fooBar }}', } }, rows: webhook.headers, allowAdd: true, allowDelete: true, allowReorder: true, addRowLabel: 'Add a header'|t('webhooks'), }) }}

{{ forms.checkboxField({ label: 'Send a custom payload'|t('webhooks'), name: 'customPayload', checked: webhook.payloadTemplate, toggle: 'custom-payload', reverseToggle: 'standard-payload' }) }}
{{ forms.textareaField({ label: 'Extra User Attributes'|t('webhooks'), instructions: 'List of additional attributes for the logged-in user that should be included in the webhook body.'|t('webhooks') ~ ' ' ~ '(Place separate attributes on new lines.)'|t('webhooks'), id: 'user-attributes', name: 'userAttributes', placeholder: 'photo.url', class: 'code nicetext', value: webhook.userAttributes, errors: webhook.getErrors('userAttributes') }) }} {{ forms.textareaField({ label: 'Extra Sender Attributes'|t('webhooks'), instructions: 'List of additional attributes for the event sender that should be included in the webhook body.'|t('webhooks') ~ ' ' ~ '(Place separate attributes on new lines.)'|t('webhooks'), id: 'sender-attributes', name: 'senderAttributes', placeholder: 'author.email', class: 'code nicetext', value: webhook.senderAttributes, errors: webhook.getErrors('senderAttributes') }) }} {{ forms.textareaField({ label: 'Extra Event Attributes'|t('webhooks'), instructions: 'List of additional attributes for the event properties that should be included in the webhook body.'|t('webhooks') ~ ' ' ~ '(Place separate attributes on new lines.)'|t('webhooks'), id: 'event-attributes', name: 'eventAttributes', class: 'code nicetext', value: webhook.eventAttributes, errors: webhook.getErrors('eventAttributes') }) }}
{{ forms.textareaField({ label: 'Payload Template'|t('webhooks'), instructions: 'Enter a custom Twig template that outputs the payload body. An `event` variable will be present, set to the event that was triggered.'|t('webhooks'), id: 'json-payload-template', name: 'payloadTemplate', class: 'code nicetext', rows: 10, value: webhook.payloadTemplate, errors: webhook.getErrors('payloadTemplate') }) }}
{% endblock %} {% block details %}
{% if groupOptions|length > 1 %} {{ forms.selectField({ first: true, label: 'Group'|t('webhooks'), id: 'group', name: 'groupId', value: webhook.groupId, options: groupOptions }) }} {% endif %} {{ forms.lightswitchField({ label: 'Enabled'|t('webhooks'), id: 'enabled', name: 'enabled', on: webhook.enabled }) }}
{% endblock %}