|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\http_webhooks\Form; |
| 4 | + |
| 5 | +use Drupal\Core\Form\ConfigFormBase; |
| 6 | +use Drupal\Core\Form\FormStateInterface; |
| 7 | + |
| 8 | +/** |
| 9 | + * Class OutgoingWebhookConfigForm. |
| 10 | + */ |
| 11 | +class OutgoingWebhookConfigForm extends ConfigFormBase { |
| 12 | + |
| 13 | + /** |
| 14 | + * {@inheritdoc} |
| 15 | + */ |
| 16 | + protected function getEditableConfigNames() { |
| 17 | + return [ |
| 18 | + 'http_webhooks.outgoing_config', |
| 19 | + ]; |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * {@inheritdoc} |
| 24 | + */ |
| 25 | + public function getFormId() { |
| 26 | + return 'outgoing_webhook_config_form'; |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * {@inheritdoc} |
| 31 | + */ |
| 32 | + public function buildForm(array $form, FormStateInterface $form_state) { |
| 33 | + $config = $this->config('http_webhooks.outgoing_config'); |
| 34 | + $form['secret'] = [ |
| 35 | + '#type' => 'password', |
| 36 | + '#title' => $this->t('Secret'), |
| 37 | + '#description' => $this->t('The secret'), |
| 38 | + '#maxlength' => 255, |
| 39 | + '#size' => 64, |
| 40 | + '#default_value' => $config->get('http_webhooks.outgoing.secret'), |
| 41 | + ]; |
| 42 | + $form['url'] = [ |
| 43 | + '#type' => 'url', |
| 44 | + '#title' => $this->t('URL of the webhook'), |
| 45 | + '#description' => $this->t('The URL to make the POST request'), |
| 46 | + '#default_value' => $config->get('http_webhooks.outgoing.url'), |
| 47 | + ]; |
| 48 | + return parent::buildForm($form, $form_state); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * {@inheritdoc} |
| 53 | + */ |
| 54 | + public function submitForm(array &$form, FormStateInterface $form_state) { |
| 55 | + parent::submitForm($form, $form_state); |
| 56 | + |
| 57 | + $this->config('http_webhooks.outgoing_config') |
| 58 | + ->set('http_webhooks.outgoing.secret', $form_state->getValue('secret')) |
| 59 | + ->set('http_webhooks.outgoing.url', $form_state->getValue('url')) |
| 60 | + ->save(); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments