-
Notifications
You must be signed in to change notification settings - Fork 0
/
cambridge_person_profile.module
106 lines (91 loc) · 3.46 KB
/
cambridge_person_profile.module
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
<?php
/**
* @file
* Code for the Person Profile feature.
*/
include_once 'cambridge_person_profile.features.inc';
/**
* Implements hook_theme_registry_alter().
*/
function cambridge_person_profile_theme_registry_alter(&$theme_registry) {
//add the custom node tpl in our module to the theme registry
$theme_registry['node__cambridge_person_profile'] = array(
'template' => drupal_get_path('module', 'cambridge_person_profile') . '/templates/node--cambridge-person-profile',
'type' => 'module',
);
$theme_registry['node__cambridge_person_profile_teaser'] = array(
'template' => drupal_get_path('module', 'cambridge_person_profile') . '/templates/node--cambridge-person-profile-teaser',
'type' => 'module',
);
//add the custom theme tpl in our module to the theme registry
$theme_registry['field__field_person_positions__cambridge_person_profile'] = array(
'template' => drupal_get_path('module', 'cambridge_person_profile') . '/templates/field--field-person-positions--cambridge-person-profile',
'type' => 'module',
);
}
function cambridge_person_profile_preprocess_node(&$vars) {
$a = 1;
if ($vars['teaser'] && $vars['type'] == 'cambridge_person_profile') {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '_teaser';
}
}
/**
* instance of hook _enable()
* Adjust the weight of this module if the cambridge_teasers module is installed as the two conflict on teaser themeing.
*/
function cambridge_person_profile_enable() {
$result = db_select('system', 's')
->condition('s.type', 'module')
->condition('s.status', 1)
->condition('s.name', 'cambridge_teasers')
->fields('s', array('weight', 'info', 'name'))
//->orderBy('weight', 'ASC')
->execute();
$teaser_module_object = $result->fetchObject();
print_r($teaser_module_object);
//if the cambridge_teaser module exists and is enabled on our site, we must increase the weight of this module accordingly
if (!empty($teaser_module_object)) {
$new_person_profile_module_weight = $teaser_module_object->weight + 1;
//set the weight of this module to it's new value
$query = db_update('system')
->fields(array(
'weight' => $new_person_profile_module_weight
))
->where(
'name = :module_name',
array('module_name' => 'cambridge_person_profile')
)
->execute();
}
}
/**
* instance of hook _modules_enabled()
* @param $modules
*/
function cambridge_person_profile_modules_enabled($modules) {
//if the cambridge_teasers module was just installed, need to set the weight of this module to heavier than the teasers module
//or the display of person profile content will not work in teaser mode.
if (in_array('cambridge_teasers', $modules)) {
$result = db_select('system', 's')
->condition('s.type', 'module')
->condition('s.status', 1)
->condition('s.name', 'cambridge_teasers')
->fields('s', array('weight', 'info', 'name'))
//->orderBy('weight', 'ASC')
->execute();
$teaser_module_object = $result->fetchObject();
if (isset($teaser_module_object)) {
$new_person_profile_module_weight = $teaser_module_object->weight + 1;
//set the weight of this module to it's new value
$query = db_update('system')
->fields(array(
'weight' => $new_person_profile_module_weight
))
->where(
'name = :module_name',
array('module_name' => 'cambridge_person_profile')
)
->execute();
}
}
}