-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstanford_soe_regions.module
200 lines (188 loc) · 6.21 KB
/
stanford_soe_regions.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
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
<?php
/**
* @file
* Add regions to SOE
*/
/**
* Implements hook_define_region().
*/
function stanford_soe_regions_define_regions() {
$region['full_width_super_hero'] = array(
'title' => 'Full Width Super Hero',
//'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/soe_regions.js',
//'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_full_width_super_hero_render_region',
);
$region['content_body_lower'] = array(
'title' => 'Content Body Lower',
//'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/soe_regions.js',
//'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_content_body_lower_render_region',
);
$region['full_width_middle'] = array(
'title' => 'Full Width Middle',
//'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/soe_regions.js',
//'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_full_width_middle_render_region',
);
$region['content_body_bottom'] = array(
'title' => 'Content Body Bottom',
//'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/stanford_soe_regions.js',
//'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_content_body_bottom_render_region',
);
$region['digital_magazine_menu'] = array(
'title' => 'Digital Magazine Menu',
//'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/stanford_soe_regions.js',
//'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_digital_magazine_menu_render_region',
);
$region['digital_magazine_megamenu'] = array(
'title' => 'Digital Magazine Megamenu',
'js' => drupal_get_path('module', 'stanford_soe_regions') . '/js/stanford_soe_regions_megamenu.js',
'css' => drupal_get_path('module', 'stanford_soe_regions') . '/css/soe_regions.css',
'render_callback' => '_digital_magazine_megamenu_render_region',
);
return $region;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _full_width_super_hero_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _content_body_lower_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _full_width_middle_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _content_body_bottom_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _digital_magazine_menu_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Helper function for rendering the blocks in this region.
*/
function _digital_magazine_megamenu_render_region($block_html, $block) {
$renderable_block = _block_get_renderable_array(array($block));
$output = drupal_render($renderable_block);
return $output;
}
/**
* Implements hook_page_alter().
*/
function stanford_soe_regions_page_alter(&$page) {
//Printing in page template so no need for appending to the page_bottom variable.
unset($page['page_bottom']['regions_module']);
}
/**
* Implements hook_preprocess_page().
*/
function stanford_soe_regions_preprocess_page(&$variables) {
// TODO: Add additional logic to swap page template based on DM context here.
if (!path_is_admin(current_path())) {
$variables['theme_hook_suggestions'][] = 'digital_magazine_page';
}
$path_alias = drupal_get_path_alias(current_path());
$magazine_parts = explode('/', $path_alias);
if (in_array('magazine', $magazine_parts)) {
$variables['dm_global_header'] = 'dm-global-header';
}
else {
$variables['dm_global_header'] = '';
}
}
/**
* Implements hook_theme().
*/
function stanford_soe_regions_theme() {
return array(
'digital_magazine_page' => array(
'template' => 'templates/digital-magazine-page',
'render element' => 'page'
),
'print__html' => array(
'template' => 'templates/print--html',
'render element' => 'page'
),
);
}
/**
* Implements hook_form_alter().
*/
function stanford_soe_regions_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'ctools_export_ui_edit_item_form') {
//Since we are adding regions programmatically, we fix the order in the context reactions list here.
$order = array(
'#tree',
'#theme',
'admin_shortcuts',
'full_width_super_hero',
'global_header',
'header',
'navigation',
'search_box',
'digital_magazine_menu',
'digital_magazine_megamenu',
'fullwidth_top',
'main_top',
'main_upper',
'sidebar_first',
'highlighted',
'help',
'content_top',
'content_upper',
'content',
'content_row2',
'content_col2-1',
'content_col2-2',
'content_row3',
'content_col3-1',
'content_col3-2',
'content_col3-3',
'content_row4',
'content_col4-1',
'content_col4-2',
'content_col4-3',
'content_col4-4',
'content_lower',
'content_bottom',
'sidebar_second',
'main_lower',
'main_bottom',
'content_body_lower',
'full_width_middle',
'content_body_bottom',
'fullwidth_bottom',
'footer',
);
uksort($form['reactions']['plugins']['block']['blocks'], function($key1, $key2) use ($order) {
return (array_search($key1, $order) > array_search($key2, $order));
});
}
}