This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cos_impact_blocks.module
324 lines (307 loc) · 9.45 KB
/
cos_impact_blocks.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
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?php
/**
* @file
* Creates a block to house the Social Media Icons.
*/
/**
* Implements hook_permission().
*/
function cos_impact_blocks_permission() {
return array(
'administer impact tools' => array(
'title' => t('Administer Impact Tools Settings'),
'description' => t('Perform tasks related to the Impact Tools block'),
),
);
}
/**
* Implements hook_menu().
*/
function cos_impact_blocks_menu() {
$items = array();
$items['admin/config/impact'] = array(
'title' => 'Impact Tools Box',
'description' => 'Administer Impact Blocks',
'access arguments' => array('administer impact tools'),
);
$items['admin/config/impact/manage'] = array(
'title' => 'Impact Tools Settings',
'description' => 'Change the icons, links and sort order of the tools block',
'access arguments' => array('administer impact tools'),
'page callback' => 'drupal_get_form',
'page arguments' => array('cos_impact_tools_settings_form'),
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'cos_impact_tools_settings.inc',
);
$items['admin/config/impact/add'] = array(
'title' => 'Add new Impact Box.',
'description' => 'Add a new Impact tool box to the home page block.',
'page callback' => 'drupal_get_form',
'page arguments' => array('cos_impact_add_form'),
'access arguments' => array('administer impact tools'),
'type' => MENU_CALLBACK,
'file' => 'cos_impact_tools.add.inc',
);
$items['admin/config/impact/delete/%row_data'] = array(
'title' => 'Remove an Impact Box.',
'description' => 'Remove an Impact tool box to the home page block.',
'page callback' => 'drupal_get_form',
'page arguments' => array('cos_impact_remove_row_form', 4),
'access arguments' => array('administer impact tools'),
'type' => MENU_CALLBACK,
'file' => 'cos_impact_tools.remove.inc',
);
return $items;
}
/**
* Implements block_info()
*
* This will create my blocks and place them into the appropriate sections.
*/
function cos_impact_blocks_block_info() {
$blocks['impact_social'] = array(
'info' => t('Impact Social Icons'),
'status' => TRUE,
'region' => 'nav',
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => '<front>',
);
$blocks['impact_tools'] = array(
'info' => t('Impact Tools'),
'status' => TRUE,
'region' => 'sidebar_first',
'visibility' => BLOCK_VISIBILITY_LISTED,
'pages' => '<front>',
);
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function cos_impact_blocks_block_configure($delta = '') {
$form = array();
if ($delta == 'impact_social') {
$form['imp_twitter'] = array(
'#type' => 'textfield',
'#title' => t('Twitter URL'),
'#size' => 60,
'#description' => t('Enter your groups Twitter page url.'),
'#default_value' => variable_get('imp_twitter'),
);
$form['imp_facebook'] = array(
'#type' => 'textfield',
'#title' => t('Facebook URL'),
'#size' => 60,
'#description' => t("Enter your facebook's group page url."),
'#default_value' => variable_get('imp_facebook'),
);
$form['imp_instagram'] = array(
'#type' => 'textfield',
'#title' => t('Instagram URL'),
'#size' => 60,
'#description' => t('Enter your groups Instagram page url.'),
'#default_value' => variable_get('imp_instagram'),
);
/*
// Start container for links
$form['link_container'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('some-class')),
'#tree' => TRUE,
);
$form['link_container']['link_twitter'] = array(
'#type' => 'link_field',
'#title' => t('Twitter URL'),
'#field_name' => 'link_field_twitter',
'#language' => 'und',
'#field_parents' => array(),
'#delta' => 0,
'#description' => t('Enter your group\'s twitter page url.'),
'#default_value' => array(
'title' => variable_get('link_title_twitter', 'twitter'),
'url' => variable_get('link_url_twitter', ''),
),
);
$form['link_container']['link_facebook'] = array(
'#type' => 'link_field',
'#title' => t('Facebook URL'),
'#field_name' => 'link_field_facebook',
'#language' => 'und',
'#field_parents' => array(),
'#delta' => 0,
'#description' => t('Enter your facebook\'s group page url.'),
'#default_value' => array(
'title' => variable_get('link_title_facebook', 'facebook'),
'url' => variable_get('link_url_facebook', ''),
),
);
$form['link_container']['link_instagram'] = array(
'#type' => 'link_field',
'#title' => t('Instagram URL'),
'#field_name' => 'link_field_instagram',
'#language' => 'und',
'#field_parents' => array(),
'#delta' => 0,
'#description' => t('Enter your group\'s Instagram page url.'),
'#default_value' => array(
'title' => variable_get('link_title_instagram', 'Instagram'),
'url' => variable_get('link_url_instagram', ''),
),
);
*/
}
return $form;
}
/**
* Implements hook_block_save().
*/
function cos_impact_blocks_block_save($delta = '', $edit = array()) {
if ($delta == 'impact_social') {
variable_set('imp_twitter', $edit['imp_twitter']);
variable_set('imp_facebook', $edit['imp_facebook']);
variable_set('imp_instagram', $edit['imp_instagram']);
// Twitter url data
// variable_set('link_title_twitter',
// $edit['link_container']['link_twitter']['title']);
// variable_set('link_url_twitter',
// $edit['link_container']['link_twitter']['url']);
// Facebook url data
// variable_set('link_title_facebook',
// $edit['link_container']['link_facebook']['title']);
// variable_set('link_url_facebook',
// $edit['link_container']['link_facebook']['url']);
// Instagram url data
// variable_set('link_title_instagram',
// $edit['link_container']['link_instagram']['title']);
// variable_set('link_url_instagram',
// $edit['link_container']['link_instagram']['url']);.
}
}
/**
* Implements hook_block_view().
*/
function cos_impact_blocks_block_view($delta = '') {
switch ($delta) {
case 'impact_social':
$block['subject'] = '';
$items = array();
$items['twitter'] = variable_get('imp_twitter');
$items['facebook'] = variable_get('imp_facebook');
$items['instagram'] = variable_get('imp_instagram');
/*
foreach($result as $title => $link){
$items[] = array(
'data' => $link,
);
}*/
$block['content'] = array(
// '#theme' => 'item_list__impact_social',.
'#theme' => 'cos_impact_social_front',
'#items' => $items,
);
/*
$block['content'] = theme(
'cos_impact_social_front', array(
'items' => $items)
);
*/
break;
/*
* This block will be for the toolbox block that will contain the
* icons for different options.
*/
case 'impact_tools':
$block['subject'] = '';
$items = array();
$query = cos_impact_contents($delta);
$i = 0;
foreach ($query as $item) {
$items[$i]['title'] = check_plain($item->title);
$items[$i]['icon'] = check_plain($item->icon);
$items[$i]['url'] = check_plain($item->url);
$i++;
}
unset($i);
/*
$block['content'] = theme(
'cos_impact_tools_front', array(
'items' => $items)
);
*/
$block['content'] = array(
'#theme' => 'cos_impact_tools_front',
'#items' => $items,
'#contextual_links' => array(
'cos_impact_blocks' => array(
'admin/config/impact/manage',
array(0),
),
),
);
break;
}
return $block;
}
/**
* Custom Function to get block content.
*/
function cos_impact_contents($which_block) {
switch ($which_block) {
case 'impact_social':
$results = array(
'twitter' => variable_get('link_url_twitter'),
'facebook' => variable_get('link_url_facebook'),
'instagram' => variable_get('link_url_instagram'),
);
return $results;
case 'impact_tools':
$query = db_select('cos_impact_blocks', 'cos')
->fields('cos', array('icon'))
->fields('cos', array('title'))
->fields('cos', array('url'))
->fields('cos', array('weight'))
->orderBy('weight', 'ASEC');
$data = $query->execute();
$results = $data;
return $results;
}
}
/**
* Implements hook_theme().
*/
function cos_impact_blocks_theme($existing, $type, $theme, $path) {
$module_path = drupal_get_path('module', 'cos_impact_blocks');
$themes['cos_impact_social_front'] = array(
'variables' => array('items' => NULL),
'template' => 'block--cos-impact-blocks--impact-social',
'path' => $module_path . '/templates',
);
$themes['cos_impact_tools_settings_form'] = array(
'render element' => 'form',
'file' => 'cos_impact_tools_settings.inc',
);
$themes['cos_impact_tools_front'] = array(
'variables' => array('items' => NULL),
'template' => 'block--cos-impact-blocks--impact-tools',
'path' => $module_path . '/templates',
);
return $themes;
}
/**
* Load a row of data from the database.
*
* @param int $row_id
* The row to load.
*
* @return mixed
* An associative array of database results.
*/
function row_data_load($row_id) {
$results = db_select('cos_impact_blocks', 'cos')
->fields('cos', array('id', 'title', 'url', 'icon'))
->condition('id', $row_id, '=')
->execute()
->fetchAssoc();
return $results;
}