-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapigee_devportal_kickstart_openbank_au.install
209 lines (187 loc) · 7.11 KB
/
apigee_devportal_kickstart_openbank_au.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/**
* @file
* Copyright 2019 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 Drupal\apigee_devportal_kickstart_openbank_au\Installer\ApigeeDevportalKickstartTasksManager;
use Drupal\apigee_devportal_kickstart_openbank_au\Installer\Form\ApigeeEdgeConfigurationForm;
use Drupal\apigee_devportal_kickstart_openbank_au\Installer\Form\OpenBankConfigurationForm;
use Drupal\apigee_devportal_kickstart_openbank_au\Installer\Form\DemoInstallForm;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\menu_link_content\Entity\MenuLinkContent;
/**
* @file
* Install, update and uninstall functions for Apigee Kickstart profile.
*/
/**
* Implements hook_install_tasks().
*/
function apigee_devportal_kickstart_openbank_au_install_tasks(&$install_state) {
// Initialize the seven theme and set it as active.
// This ensures the installation theme is maintained across tasks.
$theme = \Drupal::service('theme.initialization')->initTheme('seven');
\Drupal::theme()->setActiveTheme($theme);
$tasks = [
DemoInstallForm::class => [
'display_name' => t('Install demo content'),
'type' => 'form',
],
];
$tasks['apigee_devportal_kickstart_openbank_au_finish'] = [
'display' => FALSE,
];
return $tasks;
}
/**
* Implements hook_install_tasks_alter().
*/
function apigee_devportal_kickstart_openbank_au_install_tasks_alter(&$tasks, $install_state) {
// Do not add the apigee_edge_configure_form tasks if non-interactive install
// since drush si cannot set default values for the form.
// Use `drush key-save apigee_edge_connection_default '{\"auth_type\":\"basic\",\"organization\":\"ORGANIZATION\",\"username\":\"USERNAME\",\"password\":\"PASSWORD"}' --key-type=apigee_auth -y`
// to create a key after drush si.
if (!$install_state['interactive']) {
return;
}
$apigee_kickstart_tasks = [
ApigeeEdgeConfigurationForm::class => [
'display_name' => t('Configure Apigee Edge'),
'type' => 'form',
],
OpenBankConfigurationForm::class => [
'display_name' => t('Configure Apigee Edge'),
'type' => 'form',
],
];
// The task should run before install_configure_form which creates the user.
$tasks_copy = $tasks;
$tasks = array_slice($tasks_copy, 0, array_search('install_configure_form', array_keys($tasks))) + $apigee_kickstart_tasks + $tasks_copy;
}
/**
* Install the theme.
*
* @param array $install_state
* The install state.
*/
function apigee_devportal_kickstart_openbank_au_theme_setup(array &$install_state) {
// Clear all status messages generated by modules installed in previous step.
Drupal::messenger()->deleteByType(MessengerInterface::TYPE_STATUS);
// Set apigee_kickstart as the default theme.
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'openbank_au')
->save();
// Ensure that the install profile's theme is used.
// @see _drupal_maintenance_theme()
\Drupal::service('theme.manager')->resetActiveTheme();
// Enable the admin theme for editing content.
\Drupal::configFactory()
->getEditable('node.settings')
->set('use_admin_theme', TRUE)
->save(TRUE);
}
/**
* Run any additional tasks for the installation.
*/
function apigee_devportal_kickstart_openbank_au_finish() {
// Re-run the optional config import again since Drupal installation profile
// imports optional configuration only once.
// @see \Drupal\Core\Config\ConfigInstaller::installDefaultConfig
// @see install_install_profile()
\Drupal::service('config.installer')->installOptionalConfig();
}
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function apigee_devportal_kickstart_openbank_au_install() {
// Get profile path.
$src_path = drupal_get_path('profile', 'apigee_devportal_kickstart_openbank_au') . '/resources/files';
// Get public files directory.
$dest_path = file_default_scheme() . '://';
// Files to copy.
// Not all files are copied. So we list them here individually.
$filesets = [
'' => [
'aditya-vyas-1392552-unsplash.jpg',
'chuttersnap-255216-unsplash.png',
'donald-giannatti-671274-unsplash.jpg',
'nasa-43567-unsplash.jpg',
'nasa-43569-unsplash.jpg',
'nasa-89116-unsplash.jpg',
'spacex-1130896-unsplash.jpg',
'spacex-81773-unsplash.jpg',
'terence-burke-1417892-unsplash.jpg',
],
'default_images/' => [
'profile-default.jpg',
],
'apidoc_specs/' => [
'petstore.yaml',
],
];
// Copy files in public files directory. Note: Managed files are not desired.
foreach ($filesets as $destination => $files) {
foreach ($files as $file) {
if (file_exists($src_path . '/' . $file)) {
// If the file exists in public://, it should be skipped, as these are
// tied to media entities which hard-code the path/file.
$directory = $dest_path . $destination;
if (!empty($destination)) {
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
}
file_unmanaged_copy($src_path . '/' . $file, $directory . $file);
}
}
}
// Create a forum link.
// This cannot be added as config since uninstalling forum.module will result
// in a RouteNotFoundException.
// See https://github.com/apigee/apigee-devportal-kickstart-drupal/issues/276.
MenuLinkContent::create([
'title' => 'Forum',
'menu_name' => 'main',
'link' => ['uri' => 'internal:/forum'],
'weight' => 3,
])->save();
}
/**
* Implements hook_requirements().
*/
function apigee_devportal_kickstart_openbank_au_requirements($phase) {
$requirements = [];
// Drupal 8.8.x requires pathauto >=8.x-1.6.
// Make sure this requirement is met.
if ($pathauto = Drupal::service('extension.list.module')->get('pathauto')) {
$current_version = $pathauto->info['version'];
$required_version = '8.x-1.6';
if (!version_compare($current_version, $required_version, '>=')) {
$requirements['apigee_devportal_kickstart_openbank_au_pathauto_version'] = [
'title' => t('Apigee Devportal Kickstart'),
'description' => t('Apigee Devportal Kickstart requires <a href=":url">Pathauto</a> <em>@required_version</em>. The current version is <em>@current_version</em>. Please update to the required version to ensure future compatibility.', [
':url' => 'https://drupal.org/project/pathauto',
'@required_version' => $required_version,
'@current_version' => $current_version,
]),
'severity' => REQUIREMENT_ERROR,
];
}
}
return $requirements;
}