-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathexpress.profile
308 lines (270 loc) · 8.36 KB
/
express.profile
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
/**
* @file
* Configure Express.
*/
const MINIMUM_CORE = '7.56';
/**
* Implements hook_form_FORM_ID_alter().
*
* Allows the profile to alter the site configuration form.
*/
if (!function_exists("system_form_install_configure_form_alter")) {
function system_form_install_configure_form_alter(&$form, $form_state) {
$form['site_information']['site_name']['#default_value'] = 'express';
}
}
/**
* Implements hook_form_alter().
*
* Select the current install profile by default.
*/
if (!function_exists("system_form_install_select_profile_form_alter")) {
function system_form_install_select_profile_form_alter(&$form, $form_state) {
foreach ($form['profile'] as $key => $element) {
$form['profile'][$key]['#value'] = 'express';
}
}
}
/**
* Implements hook_install_tasks().
*/
function express_install_tasks() {
// @TODO: This looks nothing like http://cgit.drupalcode.org/drupal/tree/includes/install.core.inc?h=7.x#n525
// should it?
$tasks = array();
$tasks['express_profile_configure_form'] = array(
'display_name' => st('Configure Express profile'),
'type' => 'form',
);
$tasks['express_final'] = array();
return $tasks;
}
function express_profile_configure_form() {
$form = array();
$options = array(
'cu_core' => st('Production'),
'cu_testing_core' => st('Testing'),
'pantheon_hosting' => st('Pantheon'),
);
$form['express_core_version'] = array(
'#type' => 'radios',
'#title' => st('Which version of Express would you like to install?'),
'#description' => st('"Production" will include the "cu_core" module, Testing will include the "cu_testing_core" module, "Pantheon will include the "pantheon_hosting" module.'),
'#options' => $options,
'#default_value' => 'cu_core',
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => st('Create and Finish'),
'#weight' => 15,
);
return $form;
}
function express_profile_configure_form_submit(&$form, &$form_state) {
variable_set('express_core_version', $form_state['values']['express_core_version']);
}
/**
* Final configurations for Express.
*/
function express_final() {
// MOVED HERE TO FIX FIT-1684
module_enable(array('entityreference'));
module_enable(array('express_layout'));
// We know for sure that our database name is unique and thus, I'm using that
// to append to the email. Another option was base_path(), but that isnt
// known during the install process. $plus = str_replace('/', '_',
// trim(base_path(), '/'));
global $databases;
$plus = $databases['default']['default']['database'];
variable_set('site_mail', 'cudrupal+' . $plus . '@gmail.com');
// Place the system-main block in the content region.
$update = db_update('block')
->fields(array(
'status' => 1,
'region' => 'content',
'weight' => 0,
))
->condition('module', 'system')
->condition('delta', 'main')
->execute();
// Set subnaviagtion block title to <none>
db_query("UPDATE {block} SET title = '<none>' WHERE delta = 'site_navigation_menus-1'");
db_query("UPDATE {block} SET title = '<none>' WHERE delta = 'site_navigation_menus-4'");
// @TODO: figure out why these are enabled by default
module_disable(array('update'));
theme_disable(array('bartik'));
// Enabled cu_users and rebuild secure permissions (after a static reset).
module_enable(array('secure_permissions'));
drupal_static_reset();
module_enable(array('express_permissions'));
// Add core module based on selection from profile install form.
if ($core = variable_get('express_core_version', '')) {
module_enable(array($core));
}
// Update modules to ignore.
profile_module_manager_add_to_ignore(array('entityreference', 'express_layout', 'secure_permissions', 'express_permissions'));
// Rebuild list of content types for disable_node_menu_item.
$types = node_type_get_names();
variable_set('dnmi_content_types', array_flip($types));
drupal_flush_all_caches();
secure_permissions_rebuild();
}
/**
* Implements hook_themes_enabled().
*
* Makes sure blocks are set properly on structure/blocks for all new themes.
*/
function express_themes_enabled() {
$query = db_update('block')
->fields(array(
'region' => '-1',
'status' => '0',
))
->execute();
$query = db_update('block')
->fields(array(
'region' => 'content',
'status' => '1',
))
->condition('delta', 'main')
->execute();
$query = db_update('block')
->fields(array(
'region' => 'help',
'status' => '1',
))
->condition('delta', 'help')
->execute();
}
/**
* Implements hook_node_type_insert().
*/
function express_node_type_insert($info) {
// rebuild list of content types for disable_node_menu_item
if (!in_array($info->type, $types = variable_get('dnmi_content_types', array()))) {
$types[$info->type] = $info->type;
variable_set('dnmi_content_types', $types);
}
}
/**
* Implements hook_node_type_delete().
*/
function express_node_type_delete($info) {
if (in_array($info->type, $types = variable_get('dnmi_content_types', array()))) {
unset($types[$info->type]);
variable_set('dnmi_content_types', $types);
}
}
/**
* Implements hook_menu_alter.
* Most Express sites have a People or Person content type. There is a big difference
* between a user and content about staff, but using People for both confuses many
* site owners.
*/
function express_menu_alter(&$items) {
//@TODO: move to express_settings?
// tried but didn't work. Not sure why, but out of time.
$items['admin/people']['title'] = 'Users';
$items['admin/people']['description'] = 'Review users and roles.';
// Expose reports to SO/CE's
$items['admin/reports']['access arguments'] = array('access express reports');
$items['admin/reports/status']['access arguments'] = array('access advanced express reports');
}
function express_permission(){
return array(
'access express reports' => array(
'title' => t('Access Express Reports'),
'description' => t('View site reports.'),
),
'access advanced express reports' => array(
'title' => t('Access Advanced Express Reports'),
'description' => t('View advanced site reports.'),
),
);
}
function express_secure_permissions($role) {
$permissions = array(
'access_manager' => array(
'access express reports',
),
'administrator' => array(
'access express reports',
'access advanced express reports',
),
'configuration_manager' => array(
'access express reports',
),
'edit_my_content' => array(
'access express reports',
),
'edit_only' => array(
'access express reports',
),
'site_editor' => array(
'access express reports',
),
'site_owner' => array(
'access express reports',
),
'developer' => array(
'access express reports',
'access advanced express reports',
),
);
if (isset($permissions[$role])) {
return $permissions[$role];
}
}
/**
* Returns the image style url, image style uri, and image info
* for a given node/field.
*/
function express_get_node_thumbnail($node, $field, $image_style = 'medium') {
$node_field = $node->$field;
if (!empty($node_field)) {
$image['alt'] = $node_field[LANGUAGE_NONE][0]['alt'];
$image['path'] = image_style_url($image_style, $node_field[LANGUAGE_NONE][0]['uri']);
$image['uri'] = image_style_path($image_style, $node_field[LANGUAGE_NONE][0]['uri']);
if (!file_exists($image['uri'])) {
image_style_create_derivative(image_style_load('medium'), $node_field[LANGUAGE_NONE][0]['uri'], $image['uri']);
}
$image['info'] = image_get_info($image['uri']);
}
return $image;
}
/**
* A function that checks for known environments.
*
* @return string
*/
function express_check_known_hosts() {
// Check for Travis.
if (isset($_SERVER['TRAVIS'])) {
return 'travis';
}
// Check for Pantheon.
elseif (defined('PANTHEON_ENVIRONMENT')) {
return 'pantheon';
}
// Check for UCB On Prem.
elseif (isset($_SERVER['OSR_ENV'])) {
return 'ucb_on_prem_hosting';
}
// Check for NG.
elseif (isset($_SERVER['WWWNG_ENV'])) {
return 'ng_hosting';
}
// Check for Lando.
elseif (getenv('LANDO_ENV') === 'yes') {
return 'lando';
}
// Check for Valet.
elseif (getenv('VALET_ENV') === 'yes') {
return 'valet';
}
else {
return FALSE;
}
}