forked from ding2/ding_content
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathding_content.module
More file actions
315 lines (284 loc) · 9.85 KB
/
ding_content.module
File metadata and controls
315 lines (284 loc) · 9.85 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
<?php
include_once('ding_content.features.inc');
/**
* @file
* Various integration with panels to create panel panes and more.
*/
/**
* Implements hook_menu().
*/
function ding_content_menu() {
$items = array();
$items['ding_content/media'] = array(
'title' => 'Media browser list',
'description' => 'Ajax Callback for getting media',
'page callback' => 'ding_content_media_browser_list',
'access callback' => 'media_access',
'access arguments' => array('view'),
'type' => MENU_CALLBACK,
'file' => 'ding_content.admin.inc',
);
return $items;
}
/**
* Implements hook_enable().
*
* Create taxonomy vocabolary if needed.
*/
function ding_content_enable() {
// Create wysiwyg profile if needed.
if (!wysiwyg_profile_load('ding_wysiwyg')) {
$wysiwyg = array(
'format' => 'ding_wysiwyg',
'editor' => 'ckeditor',
'settings' => array(
'default' => 1,
'user_choose' => 0,
'show_toggle' => 1,
'theme' => 'advanced',
'language' => 'da',
'buttons' => array(
'default' => array(
'Bold' => 1,
'Italic' => 1,
'Underline' => 1,
'JustifyLeft' => 1,
'JustifyCenter' => 1,
'JustifyRight' => 1,
'BulletedList' => 1,
'NumberedList' => 1,
'Undo' => 1,
'Redo' => 1,
'Link' => 1,
'Unlink' => 1,
'Anchor' => 1,
'TextColor' => 1,
'BGColor' => 1,
'Blockquote' => 1,
'Cut' => 1,
'Copy' => 1,
'Paste' => 1,
'PasteText' => 1,
'PasteFromWord' => 1,
'RemoveFormat' => 1,
'Format' => 1,
'Font' => 1,
'FontSize' => 1,
'Styles' => 1,
'Table' => 1,
'CreateDiv' => 1,
),
'drupal' => array(
'media' => 1,
),
),
'toolbar_loc' => 'top',
'toolbar_align' => 'left',
'path_loc' => 'bottom',
'resizing' => 1,
'verify_html' => 1,
'preformatted' => 0,
'convert_fonts_to_spans' => 1,
'remove_linebreaks' => 1,
'apply_source_formatting' => 0,
'paste_auto_cleanup_on_paste' => 0,
'block_formats' => 'p,address,pre,h2,h3,h4,h5,h6,div',
'css_setting' => 'theme',
'css_path' => '',
'css_classes' => '',
),
);
$wysiwyg['settings'] = serialize($wysiwyg['settings']);
drupal_write_record('wysiwyg', $wysiwyg);
wysiwyg_profile_cache_clear();
}
}
/**
* Implements hook_ctools_plugin_directory().
*/
function ding_content_ctools_plugin_directory($owner, $plugin_type) {
if ($owner == 'ctools' && $plugin_type == 'content_types') {
return 'plugins/content_types';
}
}
/**
* Implements hook_media_browser_plugin_info().
*/
function ding_content_media_browser_plugin_info() {
$plugins = array();
$plugins['ding_content'] = array(
'#weight' => 0,
);
return $plugins;
}
/**
* Implementaion of hook_media_browser_plugin_view().
*/
function ding_content_media_browser_plugin_view($plugin_name, $params) {
$media_path = drupal_get_path('module', 'media');
$path = drupal_get_path('module', 'ding_content');
$params += array(
'types' => array(),
'multiselect' => FALSE,
);
switch ($plugin_name) {
case 'ding_content':
return array(
'#title' => t('Personal library'),
'#attached' => array(
'js' => array(
$media_path . '/js/plugins/media.library.js',
$path . '/js/ding_content.media.js',
),
'css' => array(
//@todo: should move this.
$media_path . '/js/plugins/media.library.css',
$path . '/css/ding_content.media.css',
),
),
'#settings' => array(
'viewMode' => 'thumbnails',
'getMediaUrl' => url('ding_content/media'),
// We should probably change this to load dynamically when requested
// via the JS file.
) + $params,
'#markup' => '<div id="container"><div id="scrollbox"><ul id="media-browser-library-list" class="media-list-thumbnails"></ul><div id="status"></div></div></div>',
);
break;
}
return array();
}
/**
* Implements hook_field_widget_info().
*/
function ding_content_field_widget_info() {
return array(
'ding_content_group_audience_library' => array(
'label' => t('Library audience'),
'field types' => array('group'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
),
'settings' => array(
),
),
);
}
/**
* Implements hook_field_widget_form().
*
* Based on og_field_widget_form().
*/
function ding_content_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $base) {
$element = $base;
$widget = $instance['widget'];
switch ($widget['type']) {
case 'ding_content_group_audience_library':
// Determine if a user may see other groups as-well.
$opt_group = FALSE;
if (user_access('administer group')) {
$opt_group = TRUE;
}
// Get all the groups divided to "content groups" and "other groups".
$audience = og_field_audience_options($opt_group);
// Get all groups that should be excluded.
$excludes = array();
// If it's an existing group, then exclude itself, as in some cases a group
// can act also as a group content, but we want to prevent associating the
// group to itself.
if (!empty($form['#' . $element['#entity_type']])) {
list($id) = entity_extract_ids($element['#entity_type'], $form['#' . $element['#entity_type']]);
if (($group = og_get_group($element['#entity_type'], $id))) {
$excludes[$group->gid] = $group->gid;
}
}
// Get default values from URL, or from the edited entity.
$default_values = og_get_context_by_url();
// Keep the group ID of the selected items, as they might be needed again,
// and we don't want to iterate over the items again.
$items_gid = array();
if (!empty($items)) {
foreach ($items as $item) {
// Some groups might be already deleted, but we don't bulk
// delete the fields of the entities associated with that group.
// So make sure the hidden selected fields are only for existing
// groups.
if (in_array($item['gid'], $audience['content groups']) || in_array($item['gid'], $audience['other groups'])) {
$default_values[$item['gid']] = $item['gid'];
$items_gid[] = $item['gid'];
}
}
}
foreach (array('content groups', 'other groups') as $key) {
if (!empty($audience[$key])) {
// Get the label un-sanitized, as they will be laster sanitized
// according to the form type.
$audience[$key] = og_label_multiple($audience[$key], FALSE);
}
}
// The group options presented to the user.
$options = array();
$hidden_selected_gids = array();
$type = 'select';
if ($opt_group) {
// Show "My groups" and "Other groups".
if ($my_groups = array_diff_key($audience['content groups'], $excludes)) {
$options += $my_groups;
}
if ($other_groups = array_diff_key($audience['other groups'], $excludes)) {
$options += $other_groups;
}
}
else {
// Show only "My groups".
$options = array_diff_key($audience['content groups'], $excludes);
// If there are items that are already selected but the user doesn't
// have access to them, we need to keep track of them.
$hidden_selected_gids = drupal_map_assoc(array_diff($items_gid, array_keys($options)));
}
if (empty($options)) {
// There are no group, so don't show any input element.
$type = 'item';
$element['#description'] = t('There are no libraries you can select from.');
$properties = array();
}
else {
if (empty($element['#description'])) {
$element['#description'] = t('Select the libraries this content should be associated with.');
}
$element['#multiple'] = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED;
// Don't make the field required, if there are no groups.
$element['#required'] = $element['#required'] && !empty($options);
$properties = _options_properties($type, $element['#multiple'], $element['#required'], $options);
// If the element isn't required and cardinality is more than 1, and there
// are some options, and a "none" option.
if (!$element['#required'] && !$element['#multiple']) {
// Use a dummy instance in order to use theme('options_none');
$dummy_instance['widget']['type'] = 'options_select';
$options = array('_none' => t('- All libraries -')) + $options;
}
}
$element += array(
// Input should be TRUE only if there are groups that can be selected.
'#input' => $type != 'item',
'#type' => $type,
'#options' => $options,
'#default_value' => $default_values,
'#attributes' => array('class' => array('group-audience')),
'#disabled' => empty($options),
// Re-use options widget element validation, to correctly transform
// submitted values from field => delta to delta => field.
// @see options_field_widget().
'#value_key' => 'gid',
'#element_validate' => $type != 'item' ? array('options_field_widget_validate') : array(),
'#properties' => $properties,
// Add OG specific context.
'#opt_group' => $opt_group,
'#audience' => $audience,
'#hidden_selected_gids' => $hidden_selected_gids,
);
$return = $element;
break;
}
return $return;
}