Newer
Older
<?php
/**
* @file
* Install, update and uninstall functions for the University of Cambridge installation profile.
*/
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function cambridge_install() {
require_once 'cambridge_base.inc';
// Force a main-menu link on Basic Pages.
variable_set('menu_force_page', TRUE);
// News articles shouldn't be promoted to front page.
variable_set('node_options_news_article', array('status'));
// Display date and author information on news articles.
variable_set('node_submitted_news_article', TRUE);
// News articles shouldn't be on a menu.
variable_set('menu_options_news_article', array());
$instances = array(
thewilkybarkid
committed
array(
'entity_type' => 'node',
'bundle' => 'page',
'field_name' => 'field_related_links',
'label' => st('Related links'),
'cardinality' => -1,
'type' => 'field_related_links',
'settings' => array(
'title' => 'required',
),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'hidden',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
);
foreach ($instances as $instance) {
field_create_instance($instance);
}
// Use the Smart Trim module for teasers.
$smart_trimmed = array(
'label' => 'hidden',
'module' => 'smart_trim',
'settings' => array(
'more_link' => 0,
'more_text' => 'Read more',
'summary_handler' => 'full',
'trim_length' => 325,
'trim_options' => array(
'text' => 'text',
),
'trim_suffix' => '...',
'trim_type' => 'chars',
),
'type' => 'smart_trim_format',
'weight' => 0,
);
foreach (array('page', 'link') as $type) {
$instance = field_info_instance('node', 'body', $type);
foreach (array('teaser', 'news_listing_item', 'vertical_teaser', 'sidebar_teaser') as $mode) {
$instance['display'][$mode] = $smart_trimmed;
}
field_update_instance($instance);
}
// Force a main-menu link on Basic Pages.
variable_set('menu_force_page', TRUE);
// Questions and Answers shouldn't be promoted to front page.
variable_set('node_options_questions_and_answers', array('status'));
// Questions and Answers shouldn't show date and author information.
variable_set('node_submitted_questions_and_answers', FALSE);
// Force a main-menu link on Questions and Answers.
variable_set('menu_force_questions_and_answers', TRUE);
// Set sensible URL alias pattern defaults.
variable_set('pathauto_node_pattern', '[node:title]');
variable_set('pathauto_node_page_pattern', '[node:menu-link:parent:url:path]/[node:title]');
variable_set('pathauto_node_link_pattern', 'link/[node:title]');
variable_set('pathauto_node_news_article_pattern', 'news/[node:title]');
variable_set('pathauto_node_questions_and_answers_pattern', '[node:menu-link:parent:url:path]/[node:title]');
// Don't let Menu Trail By Path handle breadcrumbs.
variable_set('menu_trail_by_path_breadcrumb_handling', FALSE);
// Use the media module for image field instances.
$instances = array(
field_read_instance('node', 'field_image', 'page'),
field_read_instance('node', 'field_image', 'link'),
);
foreach ($instances as $instance) {
$instance['widget']['type'] = 'media_generic';
$instance['widget']['module'] = 'media';
field_update_instance($instance);
}
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
$field = array(
'field_name' => 'field_user_name',
'label' => st('Name'),
'cardinality' => 1,
'type' => 'text',
'settings' => array(
'max_length' => 255,
),
);
field_create_field($field);
$instance = array(
'entity_type' => 'user',
'bundle' => 'user',
'field_name' => 'field_user_name',
'label' => st('Name'),
'description' => st('The user\'s real name.'),
'required' => 1,
'cardinality' => 1,
'type' => 'field_user_name',
'settings' => array(
'size' => 60,
'text_processing' => 0,
'user_register_form' => 1,
),
'widget' => array(
'weight' => -11,
),
'display' => array(
'default' => array(
'label' => 'inline',
'type' => 'text_plain',
'weight' => 1,
),
'teaser' => array(
'label' => 'inline',
'type' => 'text_plain',
'weight' => 1,
),
),
);
field_create_instance($instance);
variable_set('realname_pattern', '[user:field_user_name]');
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
// Give the admin user a real name.
db_insert('field_data_field_user_name')
->fields(
array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'und',
'delta' => 0,
'field_user_name_value' => 'Administrator',
'field_user_name_format' => NULL,
)
)
->execute();
db_insert('field_revision_field_user_name')
->fields(
array(
'entity_type' => 'user',
'bundle' => 'user',
'deleted' => 0,
'entity_id' => 1,
'revision_id' => 1,
'language' => 'und',
'delta' => 0,
'field_user_name_value' => 'Administrator',
'field_user_name_format' => NULL,
)
)
->execute();
// Transliterate Pathauto aliases.
variable_set('pathauto_transliterate', 1);
$settings = db_select('ckeditor_settings', 's')
->fields('s', array('settings'))
->condition('name', 'CKEditor Global Profile')
->execute()
->fetchField();
$settings = unserialize($settings);
// Set path to CKEditor library.
$settings['ckeditor_path'] = '%b/profiles/cambridge/libraries/ckeditor';
db_update('ckeditor_settings')
->fields(array('settings' => serialize($settings)))
->condition('name', 'CKEditor Global Profile')
->execute();
$profiles = db_select('ckeditor_settings', 's')
->fields('s')
->condition('name', array('Advanced', 'Full'), 'IN')
->execute()
->fetchAllAssoc('name');
foreach ($profiles as $name => $profile) {
$settings = unserialize($profile->settings);
// Set language to English (United Kingdom).
$settings['lang'] = 'en-uk';
// Turn off Advanced Content Filter.
$settings['js_conf'] = 'config.allowedContent = true;';
$plugins = ckeditor_load_plugins();
// Enable CKEditor Link plugin.
$settings['loadPlugins']['ckeditor_link'] = $plugins['ckeditor_link'];
db_update('ckeditor_settings')
->fields(array('settings' => serialize($settings)))
->condition('name', $name)
->execute();
}
// Add the CKEditor Link filter.
foreach (array('filtered_html', 'full_html') as $format_name) {
$format = filter_format_load($format_name);
$format->filters = filter_list_format($format_name);
foreach ($format->filters as $key => $filter) {
$format->filters[$key] = (array) $filter;
}
$format->filters['ckeditor_link_filter']['status'] = 1;
filter_format_save($format);
}
filter_formats_reset();
// Fix usernames in emails
cambridge_update_7101();
/**
* Set up the Menu Trail By Path module.
*/
function cambridge_update_7100() {
if (module_exists('menu_trail_by_path') || module_exists('menu_position')) {
return;
}
$result = module_enable(array('menu_trail_by_path'));
if (!$result) {
throw new DrupalUpdateException('Failed to enabled Menu Trail By Path module');
}
variable_set('menu_trail_by_path_breadcrumb_handling', FALSE);
}
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
322
323
324
325
/**
* Stop names appearing where usernames should in emails.
*
* See https://drupal.org/node/1827980
*/
function cambridge_update_7101() {
global $conf;
if (FALSE === module_exists('realname')) {
return;
}
$emails = array('register_admin_created_body', 'register_no_approval_required_body', 'status_activated_body');
foreach ($emails as $email) {
$key = 'user_mail_' . $email;
$current_variable = variable_get($key);
$conf[$key] = FALSE; // temporarily hide a customised message
$default_message = _user_mail_text($email, NULL, array(), FALSE); // find the default
$conf[$key] = $current_variable; // revert back
$current_message = _user_mail_text($email, NULL, array(), FALSE); // find the current
$current_message = preg_replace('~\R~u', "\n", $current_message); // normalise line endings
if ($current_message === $default_message) {
// only change cases where the message is still Drupal's default
$new_message = str_replace('username: [user:name]', 'username: [user:name-raw]', $default_message);
variable_set($key, $new_message);
}
}
}
/**
* Enable Metatag modules.
*/
function cambridge_update_7102() {
if (module_exists('metatag') || module_exists('metatags_quick') || module_exists('opengraph_meta')) {
return;
}
$result = module_enable(array('metatag', 'metatag_dc', 'metatag_views'));
if (!$result) {
throw new DrupalUpdateException('Failed to enabled Metatag modules');
}
}
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/**
* Use the Smart Trim module for teasers rather than Drupal's native trimming.
*/
function cambridge_update_7103() {
if (module_exists('smart_trim')) {
return;
}
if (FALSE === module_enable(array('smart_trim'))) {
throw new DrupalUpdateException('Failed to install Smart Trim module');
}
$smart_trimmed = array(
'label' => 'hidden',
'module' => 'smart_trim',
'settings' => array(
'more_link' => 0,
'more_text' => 'Read more',
'summary_handler' => 'full',
'trim_length' => 325,
'trim_options' => array(
'text' => 'text',
),
'trim_suffix' => '...',
'trim_type' => 'chars',
),
'type' => 'smart_trim_format',
);
foreach (array('page', 'link') as $type) {
// Make sure the body appears trimmed in teasers.
if (FALSE === node_type_get_name($type)) {
// Content type no longer exists.
continue;
}
$instance = field_info_instance('node', 'body', $type);
foreach (array('teaser', 'news_listing_item', 'vertical_teaser', 'sidebar_teaser') as $mode) {
if (
$instance['display'][$mode]['label'] !== 'hidden'
||
$instance['display'][$mode]['type'] !== 'text_summary_or_trimmed'
||
$instance['display'][$mode]['settings']['trim_length'] !== 600
) {
// Display has been changed, so don't touch it.
continue;
}
$instance['display'][$mode] = array_merge($instance['display'][$mode], $smart_trimmed);
}
field_update_instance($instance);
}
}
/**
* Set up Focus On teasers.
*/
function cambridge_update_7104() {
require_once 'cambridge_base.inc';
cambridge_base_set_up_focus_on_teasers();
}
/**
* Enable the Pathauto Persistent State module.
*/
function cambridge_update_7105() {
if (module_exists('pathauto_persist') || FALSE === module_exists('pathauto')) {
return;
}
if (FALSE === module_enable(array('pathauto_persist'))) {
throw new DrupalUpdateException('Failed to install Pathauto Persistent State module');
}
}
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/**
* Enable the CKEditor Link module
*/
function cambridge_update_7106() {
if (module_exists('ckeditor_link') || FALSE === module_exists('ckeditor')) {
return;
}
if (FALSE === module_enable(array('ckeditor_link'))) {
throw new DrupalUpdateException('Failed to install CKEditor link module');
}
$profiles = db_select('ckeditor_settings', 's')
->fields('s')
->condition('name', array('Advanced', 'Full'), 'IN')
->execute()
->fetchAllAssoc('name');
if (0 === count($profiles)) {
// Profiles have changed.
return;
}
foreach ($profiles as $name => $profile) {
$settings = unserialize($profile->settings);
$plugins = ckeditor_load_plugins();
// Enable CKEditor Link plugin.
$settings['loadPlugins']['ckeditor_link'] = $plugins['ckeditor_link'];
db_update('ckeditor_settings')
->fields(array('settings' => serialize($settings)))
->condition('name', $name)
->execute();
}
// Add the CKEditor Link filter.
foreach (array('filtered_html', 'full_html') as $format_name) {
$format = filter_format_load($format_name);
if (FALSE === $format) {
// Text format no longer exists.
continue;
}
$format->filters = filter_list_format($format_name);
foreach ($format->filters as $key => $filter) {
$format->filters[$key] = (array) $filter;
}
$format->filters['ckeditor_link_filter']['status'] = 1;
filter_format_save($format);
}
filter_formats_reset();
}