forked from apigee/apigee-m10n-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apigee_m10n.install
77 lines (68 loc) · 2.41 KB
/
apigee_m10n.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
76
77
<?php
/**
* @file
* Copyright 2018 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
use Apigee\Edge\Exception\ApiException;
use Drupal\apigee_m10n\Monetization;
use Drupal\apigee_m10n\MonetizationInterface;
use Drupal\user\RoleInterface;
/**
* @file
* Install, update and uninstall functions for Apigee Monetization.
*/
/**
* Implements hook_requirements().
*/
function apigee_m10n_requirements($phase) {
$requirements = [];
// If monetization is disabled after module has been installed, show error on status page.
if ($phase === 'runtime') {
try {
/** @var \Drupal\apigee_m10n\MonetizationInterface $monetization */
$monetization = Drupal::service('apigee_m10n.monetization');
if (!$monetization->isMonetizationEnabled()) {
$requirements['apigee_monetization_connection_error'] = [
'title' => t('Apigee Monetization'),
'description' => t(Monetization::MONETIZATION_DISABLED_ERROR_MESSAGE),
'severity' => REQUIREMENT_ERROR,
];
}
}
catch (ApiException $exception) {
Drupal::logger('apigee_m10n')->error($exception->getMessage());
}
}
if ($phase == 'install' || $phase == 'runtime') {
if (!extension_loaded('bcmath')) {
$requirements['apigee_monetization_bcmath'] = [
'title' => t('BC Math'),
'description' => t('Apigee Monetization requires the BC Math PHP extension in order to format prices.'),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}
/**
* Implements hook_install().
*/
function apigee_m10n_install() {
// Populate the default permissions for the authenticated user.
if (Drupal::moduleHandler()->moduleExists('user')) {
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, MonetizationInterface::DEFAULT_AUTHENTICATED_PERMISSIONS);
}
}