forked from Nikeev/drupal_sendgrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendgrid.install
75 lines (66 loc) · 2.41 KB
/
sendgrid.install
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
<?php
/**
* @file
* Install, update, and uninstall functions for the sendgrid module.
*/
/**
* Implements hook_install().
*/
function sendgrid_install() {
// Set default values for config which require dynamic values.
\Drupal::configFactory()->getEditable('sendgrid.settings')
->set('sendgrid_from_email', \Drupal::config('system.site')->get('mail'))
->set('sendgrid_from_name', \Drupal::config('system.site')->get('site_name'))
->save();
}
/**
* Implements hook_uninstall().
*/
function sendgrid_uninstall() {
// Delete other variables:
$config = \Drupal::service('config.factory')->getEditable('sendgrid.settings');
$config->clear('sendgrid_api_key')->save();
$config->clear('sendgrid_filter_format')->save();
$config->clear('sendgrid_from_email')->save();
$config->clear('sendgrid_from_name')->save();
$config->clear('sendgrid_mail_template')->save();
$config->clear('sendgrid_queue_tags')->save();
$config->clear('sendgrid_url_strip_qs')->save();
$config->clear('sendgrid_process_async')->save();
$config->clear('sendgrid_batch_log_queued')->save();
$config->clear('sendgrid_queue_worker_timeout')->save();
$queue = \Drupal::queue(SENDGRID_QUEUE);
$queue->deleteQueue();
}
/**
* Implements hook_requirements()
*/
function sendgrid_requirements($phase) {
$requirements = array(
'sendgrid' => array(
'title' => t('Sendgrid'),
),
);
if ($phase == 'runtime') {
$config = \Drupal::config('sendgrid.settings');
// Check for Mandrill library.
if (\Doctrine\Common\ClassLoader::classExists($config->get('sendgrid_api_classname'))) {
$requirements['sendgrid']['description'] = t('The Sendgrid library is installed correctly.');
$requirements['sendgrid']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['sendgrid']['description'] = t('The Sendgrid library has not been installed correctly.');
$requirements['sendgrid']['severity'] = REQUIREMENT_ERROR;
}
// Check for the Mail System module.
if (\Drupal::moduleHandler()->moduleExists('mailsystem')) {
$requirements['sendgrid']['description'] = t('The Mail System module is installed.');
$requirements['sendgrid']['severity'] = REQUIREMENT_OK;
}
else {
$requirements['sendgrid']['description'] = t('The Mail System module is required for Sendgrid.');
$requirements['sendgrid']['severity'] = REQUIREMENT_ERROR;
}
}
return $requirements;
}