media.media.inc
3.93 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
<?php
/**
* @file
* Media module integration for the Media module.
*/
/**
* Implements hook_media_browser_plugin_info().
*/
function media_media_browser_plugin_info() {
$plugins = array();
// @TODO: Should we add a permission around this?
$plugins['library'] = array(
'#weight' => 10,
);
if (user_access('administer media') || user_access('edit media')) {
$plugins['upload'] = array(
'#weight' => -10,
);
}
return $plugins;
}
/**
* Implements hook_media_browser_plugin_view().
*/
function media_media_browser_plugin_view($plugin_name, $params) {
$path = drupal_get_path('module', 'media');
$params += array(
'types' => array(),
'multiselect' => FALSE,
);
// The multiselect parameter is a string. So we check to see if it is set and
// adjust the local variable accordingly.
if ($params['multiselect'] != 'false' && $params['multiselect'] !== FALSE) {
$params['multiselect'] = TRUE;
}
$redirect = array('media/browser', array('query' => array('render' => 'media-popup')));
switch ($plugin_name) {
case 'upload':
$attached = array();
if ($params['multiselect'] && module_exists('plupload')) {
$upload_form_id = 'media_add_upload_multiple';
$attached['js'] = array($path . '/js/plugins/media.upload_multiple.js');
}
else {
$upload_form_id = 'media_add_upload';
}
module_load_include('inc', 'media', 'includes/media.pages');
$upload_form = drupal_get_form($upload_form_id, $params);
return array(
'#title' => t('Upload'),
'form' => array($upload_form),
'#attached' => $attached,
);
break;
case 'library':
return array(
'#title' => t('Library'),
'#attached' => array(
'js' => array(
$path . '/js/plugins/media.library.js',
),
'css' => array(
//@todo: should move this.
$path . '/js/plugins/media.library.css',
),
),
'#settings' => array(
'viewMode' => 'thumbnails',
'getMediaUrl' => url('media/browser/list'),
// 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_media_display_types().
*
* This is used to display media in different ways on the admin section.
* Perhaps should be merged in with the browser display.
*/
function media_media_display_types() {
$path = drupal_get_path('module', 'media');
$display_types = array();
$display_types['list'] = array(
'title' => t('List'),
'description' => t('Display as a list.'),
'icon' => $path . '/images/display-list.png',
'icon_active' => $path . '/images/display-list-active.png',
'callback' => 'media_admin_list',
'file' => drupal_get_path('module', 'media') . '/includes/media.admin.inc',
);
$display_types['thumbnails'] = array(
'title' => t('Thumbnails'),
'description' => t('Display as thumbnails.'),
'icon' => $path . '/images/display-thumbnails.png',
'icon_active' => $path . '/images/display-thumbnails-active.png',
'callback' => 'media_admin_thumbnails',
'file' => drupal_get_path('module', 'media') . '/includes/media.admin.inc',
);
return $display_types;
}
/**
* Implements hook_media_operations().
*/
function media_media_operations() {
$operations = array(
'delete' => array(
'label' => t('Delete'),
'callback' => NULL,
),
'edit' => array(
'label' => t('Edit'),
'callback' => NULL,
'redirect' => 'media/%fids/multiedit'
),
);
if (!module_exists('multiform')) {
// If the multiform module is not installed, do not show this option.
unset($operations['edit']);
}
return $operations;
}