-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontenttools.module
More file actions
335 lines (294 loc) · 8.36 KB
/
contenttools.module
File metadata and controls
335 lines (294 loc) · 8.36 KB
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
335
<?php
/**
* @file
* Provides enhanced node navigation to replace the primary tabs.
*
* Also provides a floating palette for working with content.
* The palette provides some of the administrative form features
* normally hidden in the vertical tabs when creating/editing a
* node in a floating palette. For example, adding tags,
* setting published status, etc.
*
* @author: Adam Kempler <akempler@gmail.com>
*/
/**
* Implements hook_init().
*
* @todo provide error if fontawesome not found.
*/
function contenttools_init() {
$cdn = variable_get('contentpalette_fontawesome_cdn', 1);
if ($cdn) {
drupal_add_css('http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(
'type' => 'external',
'group' => CSS_DEFAULT,
'every_page' => TRUE,
));
}
else {
// Check locally for fontawesome.
drupal_add_css('//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', array(
'group' => CSS_DEFAULT,
'every_page' => TRUE,
));
// Error if not found.
}
}
/**
* Implements hook_menu().
*/
function contenttools_menu() {
$items = array();
$items['admin/config/user-interface/contenttools'] = array(
'title' => 'ContentTools settings',
'description' => 'Congigure the ContentTools module',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'contenttools_settings_form',
),
'access arguments' => array('administer contenttools'),
'access callback' => TRUE,
'file' => 'contenttools.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_permission().
*/
function contenttools_permission() {
return array(
'administer contenttools' => array(
'title' => t('Administer the ContentTools module'),
),
'view contenttools nodeinfo' => array(
'title' => t('View node info'),
'description' => t('View the node info icon and the corresponding tooltip containing info about the node.'),
),
);
}
/**
* Implements hook_block_info().
*/
function contenttools_block_info() {
$blocks['contenttools_create'] = array(
'info' => t('Create content'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function contenttools_block_view($delta) {
$block = array();
switch ($delta) {
case 'contenttools_create':
$block['subject'] = t('Create Content');
$block['content'] = contentcreate_block();
break;
}
return $block;
}
/**
* Implements hook_preprocess_page().
*
* Adds the content palette to the specified region.
* Removes other blocks from that region.
*/
function contenttools_preprocess_page(&$vars) {
// Remove all the sidebar blocks if we are on a node add or edit page.
$arg0 = arg(0);
$arg1 = arg(1);
$arg2 = arg(2);
// Whether or not the palette is being displayed.
$active = FALSE;
if ($arg0 == 'node' && ($arg1 == 'add' || $arg2 == 'edit') && isset($arg2)) {
$display_palette = variable_get('contentpalette_display', TRUE);
if ($display_palette) {
// Prevent displaying the content palette to users without proper permissions.
$action = ($arg1 == 'add') ? 'create' : 'edit';
$access = FALSE;
if ($action == 'edit') {
if (node_access("update", $vars['node']) === TRUE) {
$access = TRUE;
}
} else if (node_access("create", $arg2) === TRUE) {
$access = TRUE;
}
if ($access) {
$display_palette = variable_get('contentpalette_display', TRUE);
// Whether or not the palette is being displayed.
$active = TRUE;
// Add the content palette.
$content = array(
'#markup' => theme('content_palette'),
'#weight' => 40,
);
array_unshift($vars['page']['content'], $content);
}
}
}
else {
// Display the node management icons.
drupal_add_library('system', 'ui', true);
drupal_add_library('system', 'ui.tooltip', true);
$args = array();
if (isset($vars['node'])) {
$args['node'] = $vars['node'];
}
$content = array(
'#markup' => theme('contentnav', $args),
'#weight' => 40,
);
// Add the icons for managing the node to the top of the page content.
array_unshift($vars['page']['content'], $content);
}
drupal_add_js(array(
'contenttools' => array(
'contenttoolsactive' => $active,
'modulepath' => drupal_get_path('module', 'contenttools'),
),
), array(
'type' => 'setting',
));
// Override the default theme used for the tabs
// so we can insert our own html into it.
// TODO this wouldn't be necessary if I can figure out
// how to modify the "#prefix" being added to the local tasks.
$vars['tabs']['#theme'] = 'content_primary_tabs';
}
/**
* Implements hook_theme().
*/
function contenttools_theme() {
$path = drupal_get_path('module', 'contenttools');
return array(
'content_primary_tabs' => array(
// 'render element' => 'form',
'template' => 'primary_tabs',
// 'file' => 'primary_tabs',
'path' => $path . '/theme',
'variables' => array(
'variables' => NULL,
),
),
'contentnav' => array(
'template' => 'contentnav',
'file' => 'theme.inc',
'path' => $path . '/theme',
'variables' => array(
'node' => NULL,
),
),
'contentcreate_icon' => array(
'template' => 'contentcreate',
'file' => 'theme.inc',
'path' => $path . '/theme',
'variables' => array(
'node' => NULL,
),
),
'content_palette' => array(
'template' => 'content_palette',
'path' => $path . '/theme',
'variables' => array(),
'file' => 'theme.inc',
),
);
}
/**
* Display an + icon for creating content.
*
* @return string
* The html to be displayed.
*/
function contentcreate_block() {
$out = '';
$node = menu_get_object();
$out .= theme('contentcreate_icon', array('node' => $node));
return $out;
}
/**
* Provide an administrative form for controlling content.
*
* Duplicates some of the form fields used for nodes,
* and provides them in a more accessible format.
*
* @return string
* html form.
*/
function content_palette_form() {
$arg0 = arg(0);
$arg1 = arg(2);
if ($arg0 == 'node' && $arg1 == 'edit') {
// if($arg0 =='node' && ($arg1 == 'add' || $arg1 == 'edit')) {
$nid = arg(1);
$node = node_load($nid);
}
else {
$type = arg(2);
$node = new stdClass();
$node->type = $type;
node_object_prepare($node);
}
$form = array();
$form['published'] = array(
'#type' => 'checkbox',
'#title' => t('Publish'),
'#default_value' => $node->status,
'#tree' => FALSE,
);
$form['promoted'] = array(
'#type' => 'checkbox',
'#title' => t('Promoted to front page'),
'#default_value' => $node->promote,
'#tree' => FALSE,
);
$fields = field_info_instances('node', $node->type);
if (isset($fields['field_tags'])) {
$tags = array();
if (isset($node->field_tags['und'])) {
foreach ($node->field_tags['und'] as $item) {
$tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);
}
}
$form['tags'] = array(
'#type' => 'textfield',
'#default_value' => taxonomy_implode_tags($tags),
'#title' => 'Add Tags',
'#autocomplete_path' => 'taxonomy/autocomplete/field_tags',
'#maxlength' => 1024,
'#element_validate' => array(
'taxonomy_autocomplete_validate',
),
'#description' => 'Enter a comma-separated list<br />of words to describe your content.',
'#size' => 25,
);
}
$form['save2'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 15,
'#attributes' => array(
// 'onclick' => 'contentnav_publish_submit',
),
);
// '#executes_submit_callback' => FALSE!
// Stops it from submitting, but nothing works.
$form['#attributes'] = array(
'onsubmit' => 'return false',
);
return $form;
}
/**
* Implements hook_contextual_links_view_alter().
*
* Hiding the contextual tools from the Contenttools Create block
* because it overlaps the icon and makes the ui awkward.
*/
function contenttools_contextual_links_view_alter(&$element, &$items) {
if (isset($element['#element']['#block']) && $element['#element']['#block']->delta == 'contenttools_create') {
unset($element['#links']);
}
}