-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintegration_report.api.php
114 lines (105 loc) · 3.44 KB
/
integration_report.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* @file
* Api documentation for Integration Report module.
*/
declare(strict_types=1);
use Drupal\integration_report\IntegrationReportBase;
use Symfony\Component\HttpFoundation\Response;
/**
* Integration Report Example class.
*
* The Integration Report Manager will collect and instantiate this class.
*
* Register this class as a service within your module and add a tag:
*
* @code
* tags:
* - { name: integration_report }
* @endcode
*/
// @codingStandardsIgnoreStart
class MyModuleExampleIntegrationReportBase extends IntegrationReportBase {
/**
* Define the properties of the status.
*
* Required for each report class.
*
* @return array
* An array defining the status with the keys:
* - 'name' (string, required)
* The name of the status being checked.
* - 'description' (string, required)
* The description of the status being checked.
* - 'js' (string, optional)
* A javascript helper file to include on the status page.
* - 'secure_callback' (bool, optional - default: FALSE)
* Whether the status callback needs to be performed over https.
* - 'use_callback' (bool, optional - default: TRUE)
* Whether to use the standard iFrame callback method.
* - 'access' (bool, optional - default: TRUE)
* Whether the status check is available based on additional custom
* conditions such as environment or user permission.
*/
public function info(): array {
return [
// Required parameters:
'name' => $this->t('Status name'),
'description' => $this->t('Status description'),
// Optional parameters:
'js' => \Drupal::service('extension.list.module')->getPath('example_module') . '/status/example-module-status.js',
'secure_callback' => FALSE,
'use_callback' => TRUE,
'access' => TRUE,
];
}
/**
* The callback for running checks and returning responses.
*
* Required for each report unless 'use_callback' is set to FALSE in
* the info declaration.
*
* @return array
* - 'success' (bool, required)
* Whether the status check was a success or failure.
* - 'messages' (array, required)
* A list of string messages to be added to the response information
* for the test.
*
* @SuppressWarnings(PHPMD.ElseExpression)
*/
public function callback(): array {
// Perform a request on an example url.
$url = 'http://example.com';
$response = \Drupal::httpClient()->get($url, ['headers' => ['Accept' => 'text/plain']]);
$messages = [];
// Check for a 200 response and the word 'domain' in the response.
if ($response->getStatusCode() == Response::HTTP_OK && strpos($response->getBody()->getContents(), 'domain') !== FALSE) {
$success = TRUE;
$messages[] = $this->t('@url was retrieved successfully.', [
'@url' => $url,
]);
}
else {
$success = FALSE;
$messages[] = $this->t('@url was not retrieved successfully.', [
'@url' => $url,
]);
}
return [
'success' => $success,
'messages' => $messages,
];
}
/**
* Add any extra markup or javascript to the footer of the status table.
*
* Optional, not required for most status checks.
*
* @return string
* Markup to be placed in the footer of the table.
*/
public function statusPage(): string {
return '<div class="extra-status-markup">Optional footer markup</div>';
}
}