-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompro_custom.module
334 lines (299 loc) · 9.51 KB
/
compro_custom.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
325
326
327
328
329
330
331
332
333
334
<?php
/**
* @file
* Custom module to perform misc tasks.
*/
/**
* Implements hook_menu().
*/
function compro_custom_menu() {
$items['admin/config/system/compro-custom'] = array(
'title' => 'Compro Custom',
'file' => 'compro_custom.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('compro_custom_admin'),
'access arguments' => array('administer site configuration'),
);
$items['admin/config/system/compro-custom/submitted'] = array(
'title' => 'Submitted lines',
'file' => 'compro_custom.admin.inc',
'page callback' => 'drupal_get_form',
'page arguments' => array('compro_custom_submitted'),
'access arguments' => array('administer content types'),
);
return $items;
}
/**
* Implements hook_page_build().
*/
function compro_custom_page_build(&$page) {
// Conditionally add CSS, based on admin screen.
$compro_custom = variable_get('compro_custom', '');
if (isset($compro_custom['icon_enable']) && $compro_custom['icon_enable']) {
if (isset($compro_custom['icon_neg']) && $compro_custom['icon_neg']) {
drupal_add_css(drupal_get_path('module', 'compro_custom') . '/icons/compro_custom_neg.css', array(
'every_page' => TRUE,
));
}
else {
drupal_add_css(drupal_get_path('module', 'compro_custom') . '/icons/compro_custom.css', array(
'every_page' => TRUE,
));
}
}
}
/**
* Implements hook_block_info().
*/
function compro_custom_block_info() {
return array(
'copyright' => array(
'info' => t('Copyright Notice'),
),
'social_share' => array(
'info' => t('Social share'),
),
);
}
/**
* Implements hook_block_view().
*/
function compro_custom_block_view($delta = '') {
$block = array('subject' => NULL, 'content' => NULL);
switch ($delta) {
case 'copyright':
$block['content'] = '© ' . date('Y') . ' ' . variable_get('site_name') .
', ' . t('All Rights Reserved.');
break;
case 'social_share':
global $base_url;
$page_url = $base_url . '/' . request_path();
$page_title = drupal_get_title();
$block['subject'] = t('Share this');
$block['content'] = '<div class="social">' .
l(
t('Facebook'), 'https://www.facebook.com/sharer/sharer.php', array(
'query' => array(
'u' => $page_url,
),
)
) .
l(
t('Twitter'),
'https://twitter.com/intent/tweet', array(
'query' => array(
'url' => $page_url,
'text' => $page_title,
),
)
) .
l(
t('LinkedIn'),
'http://www.linkedin.com/shareArticle', array(
'query' => array(
'url' => $page_url,
'title' => $page_title,
),
)
) .
'</div>';
break;
}
return $block;
}
/**
* Override the blockify standard logo block
*/
function theme_compro_custom_logo($variables) {
$site_name = filter_xss_admin(variable_get('site_name', 'Drupal'));
// Strip the base_path from the beginning of the logo path.
$path = preg_replace('|^' . base_path() . '|', '', $variables['logo_path']);
// Link path.
$compro_custom = variable_get('compro_custom', '');
$link_path = isset($compro_custom['logo']['url']) ? $compro_custom['logo']['url'] : '<front>';
$image = array(
'#theme' => 'image',
'#path' => $path,
'#alt' => t('!site_name', array(
'!site_name' => $site_name,
)),
);
$h_open = '';
$h_close = '';
$is_h = isset($compro_custom['logo']['heading']) ? $compro_custom['logo']['heading'] : 1;
if ($is_h) {
$h_open = '<h1 id="site-name">';
$h_close = '</h1>';
}
return $h_open . l(render($image), $link_path, array(
'html' => TRUE,
'attributes' => array(
'class' => array('logo'),
'id' => 'logo',
'rel' => 'home',
'title' => check_plain(isset($compro_custom['logo']['title']) ? $compro_custom['logo']['title'] : $site_name . ' home'),
),
)) . $h_close;
}
/**
* Implements hook_theme_registry_alter().
*/
function compro_custom_theme_registry_alter(&$theme_registry) {
$theme_registry['blockify_logo']['function'] = 'theme_compro_custom_logo';
}
/**
* Implements hook_entity_info_alter().
*/
function compro_custom_entity_info_alter(&$entity_info) {
// The view modes we want to add to all entities.
$modes = array('teaser', 'small');
// Add views modes for all types.
foreach ($entity_info as $key => $value) {
foreach ($modes as $mode) {
if (!isset($entity_info[$key]['view modes'][$mode])) {
$entity_info[$key]['view modes'][$mode] = array(
'label' => t('@mode', array('@mode' => ucwords($mode))),
'custom settings' => TRUE,
);
}
}
}
}
/**
* Implements hook_preprocess_node().
*/
function compro_custom_preprocess_node(&$vars) {
$vars['theme_hook_suggestions'][] = 'node__' . $vars['view_mode'];
$vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
}
/**
* Implement hook_field_formatter_info().
*/
function compro_custom_field_formatter_info() {
return array(
'compro_custom_file_link' => array(
'label' => t('Link'),
'field types' => array('file'),
'settings' => array(
'compro_custom_link_title' => '',
'compro_custom_link_class' => '',
),
),
);
}
/**
* Implements hook_field_formatter_settings_form().
*/
function compro_custom_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
if (isset($instance['display']['default']['type']) && $instance['display']['default']['type'] == 'compro_custom_file_link') {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = array();
$element['compro_custom_link_title'] = array(
'#type' => 'textfield',
'#title' => t('Link title'),
'#description' => t('Enter an optional link title to be shown instead of file name'),
'#default_value' => $settings['compro_custom_link_title'],
);
$element['compro_custom_link_class'] = array(
'#type' => 'textfield',
'#title' => t('Class'),
'#description' => t('Enter an optional class to be applied to the link'),
'#default_value' => $settings['compro_custom_link_class'],
);
return $element;
}
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function compro_custom_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
if ($instance['display']['default']['type'] == 'compro_custom_file_link') {
$summary = t('Displays a title link');
}
return $summary;
}
/**
* Implements hook_field_formatter_view().
*/
function compro_custom_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$settings = $display['settings'];
if ($instance['display']['default']['type'] == 'compro_custom_file_link') {
// Loop through items
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'link',
'#text' => $settings['compro_custom_link_title'] ? $settings['compro_custom_link_title'] : $item['filename'],
'#path' => file_create_url($item['uri']),
'#options' => array(
'attributes' => array('class' => array($settings['compro_custom_link_class'] ? $settings['compro_custom_link_class'] : '')),
'html' => FALSE,
),
);
}
}
return $element;
}
/**
* Implements hook_field_extra_fields().
*/
function compro_custom_field_extra_fields() {
$entity_info = entity_get_info();
$extra = array();
// Go through all the entity types and add extra fields for display.
foreach ($entity_info as $type => $info) {
if ($type == 'node') {
foreach ($info['bundles'] as $bundle => $bundle_info) {
$extra[$type][$bundle] = array(
'display' => array(
'compro_submitted' => array(
'label' => t('Submitted'),
'description' => t('Author attribution for the content.'),
'weight' => 0,
),
'compro_links' => array(
'label' => t('Links'),
'description' => t('Node links, like "Read more".'),
'weight' => 0,
),
),
'form' => array(
'compro_submitted' => array(
'label' => t('Submitted'),
'description' => t('Author attribution for the content.'),
'edit' => l('Edit', 'admin/config/system/compro-custom/submitted'),
'weight' => 0,
),
),
);
}
}
}
return $extra;
}
/**
* Implements hook_node_view().
*/
function compro_custom_node_view($node, $view_mode, $langcode) {
$extra = field_extra_fields_get_display('node', $node->type, $view_mode);
$su = 'compro_submitted';
$li = 'compro_links';
if (isset($extra[$su]) && isset($extra[$su]['visible']) && $extra[$su]['visible']) {
$sub = variable_get('compro_submitted', '');
$sub_line = 'Submitted by [node:author:name] on [node:created]';
if (isset($sub[$node->type])) {
$sub_line = $sub[$node->type];
}
$node->content[$su] = array(
'#prefix' => '<div class="submitted">',
'#markup' => token_replace($sub_line, array('node' => $node)),
'#suffix' => '</div>',
);
}
if (isset($extra[$li]) && isset($extra[$li]['visible']) && $extra[$li]['visible']) {
$node->content[$li] = $node->content['links'];
}
}