Skip to content

Commit 6bc2237

Browse files
committed
chore: initial commit with template
0 parents  commit 6bc2237

File tree

10 files changed

+204
-0
lines changed

10 files changed

+204
-0
lines changed

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for XDebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9000
12+
},
13+
{
14+
"name": "Launch currently open script",
15+
"type": "php",
16+
"request": "launch",
17+
"program": "${file}",
18+
"cwd": "${fileDirname}",
19+
"port": 9000
20+
}
21+
]
22+
}

composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "http_webhooks",
3+
"type": "drupal-module",
4+
"description": "HTTP Webhooks",
5+
"keywords": [
6+
],
7+
"homepage": "https://www.drupal.org/project/http_webhooks",
8+
"minimum-stability": "dev",
9+
"support": {
10+
"issues": "https://www.drupal.org/project/issues/http_webhooks",
11+
"source": "http://cgit.drupalcode.org/http_webhooks",
12+
},
13+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
http_webhooks:
2+
outgoing:
3+
secret: ''
4+
url: ''

http_webhooks.info.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: 'HTTP Webhooks'
2+
type: module
3+
description: 'HTTP Webhooks'
4+
core: 8.x
5+
package: 'Web services'

http_webhooks.links.menu.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
http_webhooks.outgoing_webhook_config_form:
2+
title: 'Custom webhooks'
3+
route_name: http_webhooks.outgoing_webhook_config_form
4+
description: 'Manage webhooks'
5+
parent: system.admin_config_system
6+
weight: 99

http_webhooks.module

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Contains http_webhooks.module.
6+
*/
7+
8+
use Drupal\Core\Routing\RouteMatchInterface;
9+
10+
/**
11+
* Implements hook_help().
12+
*/
13+
function http_webhooks_help($route_name, RouteMatchInterface $route_match) {
14+
switch ($route_name) {
15+
// Main module help for the http_webhooks module.
16+
case 'help.page.http_webhooks':
17+
$output = '';
18+
$output .= '<h3>' . t('About') . '</h3>';
19+
$output .= '<p>' . t('HTTP Webhooks') . '</p>';
20+
return $output;
21+
22+
default:
23+
}
24+
}
25+
26+
/**
27+
* Implements hook_theme().
28+
*/
29+
function http_webhooks_theme() {
30+
return [
31+
'http_webhooks' => [
32+
'render element' => 'children',
33+
],
34+
];
35+
}

http_webhooks.routing.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
http_webhooks.outgoing_webhook_config_form:
2+
path: '/admin/config/http_webhooks'
3+
defaults:
4+
_form: '\Drupal\http_webhooks\Form\OutgoingWebhookConfigForm'
5+
_title: 'OutgoingWebhookConfigForm'
6+
requirements:
7+
_permission: 'access administration pages'
8+
options:
9+
_admin_route: TRUE
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
}

templates/http-webhooks.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- Add you custom twig html here -->

tests/src/Functional/LoadTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Drupal\Tests\http_webhooks\Functional;
4+
5+
use Drupal\Core\Url;
6+
use Drupal\Tests\BrowserTestBase;
7+
8+
/**
9+
* Simple test to ensure that main page loads with module enabled.
10+
*
11+
* @group http_webhooks
12+
*/
13+
class LoadTest extends BrowserTestBase {
14+
15+
/**
16+
* Modules to enable.
17+
*
18+
* @var array
19+
*/
20+
public static $modules = ['http_webhooks'];
21+
22+
/**
23+
* A user with permission to administer site configuration.
24+
*
25+
* @var \Drupal\user\UserInterface
26+
*/
27+
protected $user;
28+
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
protected function setUp() {
33+
parent::setUp();
34+
$this->user = $this->drupalCreateUser(['administer site configuration']);
35+
$this->drupalLogin($this->user);
36+
}
37+
38+
/**
39+
* Tests that the home page loads with a 200 response.
40+
*/
41+
public function testLoad() {
42+
$this->drupalGet(Url::fromRoute('<front>'));
43+
$this->assertSession()->statusCodeEquals(200);
44+
}
45+
46+
}

0 commit comments

Comments
 (0)