Skip to content

Commit f1176e0

Browse files
committed
Settings page
1 parent b735765 commit f1176e0

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
### Added
6+
- Added a settings page in the control panel.
67
- Webhook URLs can now be set to environment variables or Twig code. ([#18](https://github.com/craftcms/webhooks/issues/18))
78
- Webhooks can now send PUT requests. ([#21](https://github.com/craftcms/webhooks/issues/21))
89

src/Plugin.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class Plugin extends \craft\base\Plugin
6565
*/
6666
const EVENT_REGISTER_FILTER_TYPES = 'registerFilterTypes';
6767

68+
/**
69+
* @inheritdoc
70+
*/
71+
public $hasCpSettings = true;
72+
6873
/**
6974
* @inheritdoc
7075
*/
@@ -189,6 +194,16 @@ public function init()
189194
});
190195
}
191196

197+
/**
198+
* @inheritdoc
199+
*/
200+
protected function settingsHtml()
201+
{
202+
return Craft::$app->getView()->renderTemplate('webhooks/_settings', [
203+
'settings' => $this->getSettings(),
204+
]);
205+
}
206+
192207
/**
193208
* @inheritdoc
194209
*/

src/Settings.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ class Settings extends Model
2121
* @var int The time delay in seconds between request attempts.
2222
*/
2323
public $attemptDelay = 60;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function defineRules(): array
29+
{
30+
return [
31+
[['maxDepth', 'maxAttempts'], 'number', 'integerOnly' => true, 'min' => 1],
32+
[['attemptDelay'], 'number', 'integerOnly' => true, 'min' => 0],
33+
];
34+
}
2435
}

src/templates/_settings.twig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{% import '_includes/forms' as forms %}
2+
3+
{{ forms.textField({
4+
first: true,
5+
id: 'max-depth',
6+
label: 'Max Payload Depth'|t('webhooks'),
7+
instructions: 'The maximum depth that the plugin should go into objects/arrays when converting them to arrays for event payloads.'|t('webhooks'),
8+
size: 5,
9+
name: 'maxDepth',
10+
value: settings.maxDepth,
11+
}) }}
12+
13+
{{ forms.textField({
14+
first: true,
15+
id: 'max-attempts',
16+
label: 'Max Attempts'|t('webhooks'),
17+
instructions: 'The maximum number of request attempts that should be made.'|t('webhooks'),
18+
size: 5,
19+
name: 'maxAttempts',
20+
value: settings.maxAttempts,
21+
}) }}
22+
23+
{{ forms.textField({
24+
first: true,
25+
id: 'attempt-delay',
26+
label: 'Attempt Delay'|t('webhooks'),
27+
instructions: 'The time delay in seconds between request attempts.'|t('webhooks'),
28+
size: 5,
29+
name: 'attemptDelay',
30+
value: settings.attemptDelay,
31+
}) }}

0 commit comments

Comments
 (0)