Newer
Older
// Hook implementations.
/**
* Implements hook_form_FORM_ID_alter().
*/
function totem_form_install_configure_form_alter(&$form, &$form_state, $form_id) {
$mail = variable_get('site_mail', 'admin@' . $_SERVER['HTTP_HOST']);
= $form['admin_account']['#collapsible']
= $form['server_settings']['#collapsible']
= $form['update_notifications']['#collapsible']
= TRUE;
$form['site_information']['#title'] = st('Community information');
$form['site_information']['site_name']['#title'] = st('Name');
$form['site_information']['site_name']['#weight'] = 10;
$form['site_information']['site_name']['#default_value'] = variable_get('site_name');
$form['site_information']['site_slogan'] = array(
'#type' => 'textfield',
'#title' => st('Tagline'),
'#description' => st(''),
'#default_value' => variable_get('site_slogan'),
'#required' => FALSE,
'#weight' => 30,
);
$form['site_information']['site_mail']['#title'] = st('Email address');
$form['site_information']['site_mail']['#weight'] = 30;
$form['site_information']['site_mail']['#default_value'] = $mail;
$form['admin_account']['#title'] = st('Community administrator');
$form['admin_account']['account']['name']['#default_value'] = $mail;
$form['admin_account']['account']['mail']['#title'] = st('Email address');
$form['admin_account']['account']['mail']['#default_value'] = $mail;
// Force standard password field (vs. pass w/confirm and strength).
$form['admin_account']['account']['pass']['#type'] = 'password';
$form['admin_account']['account']['pass']['#title'] = st('Password');
// Force username to hidden unique id mail will be copied to name field
// in hook_user_presave.
$form['admin_account']['account']['name'] = array(
'#type' => 'hidden',
'#value' => $form['admin_account']['account']['mail']['#default_value'],
);
$form['admin_account']['update_status_module'] = $form['update_notifications']['update_status_module'];
unset($form['update_notifications']);
$form['#submit'][] = 'totem_form_install_configure_form_submit';
}
/**
* Custom submit handler for settings form.
*/
function totem_form_install_configure_form_submit($form, &$form_state) {
global $user;
$userinfo = array(
'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Administrator'))),
'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Administrator'))),
);
$user = user_save($user, $userinfo);
variable_set('site_slogan', filter_xss_admin($form_state['values']['site_slogan']));
}
/**
* Implements hook_install_tasks().
*/
function totem_install_tasks($install_state) {
$tasks = array(
'_totem_install_menus' => array(),
'_totem_install_blocks' => array(),
// '_totem_install_samples' => array(
// 'display_name' => st('Install samples'),
// ),
),
);
return $tasks;
}
// Installation tasks.
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
function _totem_install_menus() {
// Only install menus if no custom client-centric mod is enabled.
$profile_custom_mod = variable_get('totem_custom');
if (!empty($profile_custom_mod)) {
return;
}
// Menus are added in totem.profile, after all Features mods have
// been installed.
$profile_intall_vars = variable_get('totem_install_temp_vars');
$items_footer = array(
array(
'link_title' => st('Featured Communities'),
'link_path' => 'communities/featured',
'menu_name' => 'footer-menu',
'weight' => 4,
),
array(
'link_title' => st('About'),
'link_path' => 'node/' . $profile_intall_vars['nid_about'],
'menu_name' => 'footer-menu',
'weight' => 5,
),
array(
'link_title' => st('Privacy Policy'),
'link_path' => 'node/' . $profile_intall_vars['nid_privacy'],
'menu_name' => 'footer-menu',
'weight' => 6,
),
array(
'link_title' => st('Terms of Use'),
'link_path' => 'node/' . $profile_intall_vars['nid_terms'],
'menu_name' => 'footer-menu',
'weight' => 7,
),
);
// Delete baseline Footer menu links.
menu_delete_links('footer-menu');
// Add Footer menu items.
foreach ($items_footer as $key => &$meta) {
menu_link_save($meta);
}
$items_main = array(
array(
'link_title' => st('Home'),
'link_path' => '<front>',
'menu_name' => 'main-menu',
'weight' => 3,
),
array(
'link_title' => st('Communities'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 4,
),
array(
'link_title' => st('Members'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 5,
),
array(
'link_title' => st('Discussions'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 6,
),
array(
'link_title' => st('Events'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 7,
),
array(
'link_title' => st('Media'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 8,
),
array(
'link_title' => st('Resources'),
'link_path' => 'user/modal/login',
'menu_name' => 'main-menu',
'weight' => 9,
),
);
// Delete baseline Main menu links.
menu_delete_links('main-menu');
// Add Main menu items.
foreach ($items_main as $key => &$meta) {
menu_link_save($meta);
}
$items_community = array(
array(
'link_title' => st('Home'),
'link_path' => 'user',
'menu_name' => 'menu-community-menu',
'weight' => 3,
),
array(
'link_title' => st('Communities'),
'link_path' => 'communities',
'menu_name' => 'menu-community-menu',
'weight' => 4,
),
array(
'link_title' => st('Members'),
'link_path' => 'members',
'menu_name' => 'menu-community-menu',
'weight' => 5,
),
array(
'link_title' => st('Discussions'),
'link_path' => 'topics',
'menu_name' => 'menu-community-menu',
'weight' => 6,
),
array(
'link_title' => st('Events'),
'link_path' => 'events',
'menu_name' => 'menu-community-menu',
'weight' => 7,
),
array(
'link_title' => st('Media'),
'link_path' => 'media',
'menu_name' => 'menu-community-menu',
'weight' => 8,
),
array(
'link_title' => st('Resources'),
'link_path' => 'resources',
'menu_name' => 'menu-community-menu',
'weight' => 9,
'expanded' => TRUE,
),
);
// Delete baseline Community menu links.
menu_delete_links('menu-community-menu');
// Add Community menu items.
foreach ($items_community as $key => &$meta) {
menu_link_save($meta);
}
// Update the menu router information.
menu_rebuild();
}
function _totem_install_blocks() {
// Get the current themes.
$theme_default = variable_get('theme_default');
$theme_admin = variable_get('admin_theme');
// Update titles.
db_update('block')
->fields(array('title' => '<none>'))
->condition('module', 'totem_common', '!=')
->execute();
// Unassign blocks from admin theme.
db_update('block')
->fields(array('region' => BLOCK_REGION_NONE))
->condition('module', 'system', '!=')
->condition('delta', 'main', '!=')
->condition('theme', $theme_admin)
->execute();
}
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
function _totem_install_samples() {
$users = array(
array(
'name' => 'irorginator@gmail.com',
'pass' => 'Tester1234',
'mail' => 'irorginator@gmail.com',
'init' => 'irorginator@gmail.com',
'status' => 1,
'access' => REQUEST_TIME,
'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Owner'))),
'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
),
array(
'name' => 'iaremanager@gmail.com',
'pass' => 'Tester1234',
'mail' => 'iaremanager@gmail.com',
'init' => 'iaremanager@gmail.com',
'status' => 1,
'access' => REQUEST_TIME,
'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Manager'))),
'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
),
array(
'name' => 'iareuser@gmail.com',
'pass' => 'Tester1234',
'mail' => 'iareuser@gmail.com',
'init' => 'iareuser@gmail.com',
'status' => 1,
'access' => REQUEST_TIME,
'field_name_first' => array(LANGUAGE_NONE => array(array('value' => 'Member'))),
'field_name_last' => array(LANGUAGE_NONE => array(array('value' => 'Community'))),
),
);
foreach ($users as $meta) {
$account = user_save(NULL, $meta);
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
db_insert('users_roles')
->fields(array('uid' => $account->uid, 'rid' => DRUPAL_AUTHENTICATED_RID))
->execute();
}
// Add community nodes for uid:2
$nodes = array(
0 => 'Open Community',
1 => 'Restricted Community',
2 => 'Closed Community',
);
foreach ($nodes as $status => $title) {
$node = new stdClass();
$node->type = 'community';
$node->uid = 2;
$node->language = LANGUAGE_NONE;
$node->title = $title;
$node->body[$node->language][0]['value'] = '';
$node->body[$node->language][0]['format'] = 'filtered_html';
$node->field_community_status[$node->language][0]['value'] = $status;
$node->field_community_featured[$node->language][0]['value'] = 1;
@node_save($node);
// Add new field_community values for uid:2, 3, 4.
$u = user_load(2);
_totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));
$u = user_load(3);
_totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));
// Grant "manager" perms to this $account.
$record = array(
'nid' => $node->nid,
'gid' => $u->uid,
'realm' => 'totem_user_node_manager',
'grant_view' => 1,
'grant_update' => 1,
'grant_delete' => 0,
);
drupal_write_record('node_access', $record);
$u = user_load(4);
_totem_common_set_field_entityreference_values('user', $u, 'field_community', array($node->nid));
}
}
function _totem_install_rebuilds() {
// Remove temp install var.
variable_del('totem_install_temp_vars');
// Grant new administrator role all permissions.
user_role_grant_permissions(3, array_keys(module_invoke_all('permission')));
// Rebuild the node access database.
node_access_rebuild(FALSE);
drupal_set_message(t('@site_name installed successfully!', array('@site_name' => variable_get('site_name'))));
}