-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_chooser_field.module
120 lines (110 loc) · 2.86 KB
/
file_chooser_field.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
<?php
/**
* @file
*/
/**
* Implements hook_file_chooser_field_plugins().
*/
function file_chooser_field_file_chooser_field_plugins() {
return [
'dropbox' => [
'name' => t('Dropbox JavaScript Chooser API'),
'phpClassName' => 'DropboxChooserAPI',
],
'google_drive' => [
'name' => t('Google Picker API'),
'phpClassName' => 'GooglePickerAPI',
],
'box' => [
'name' => t('Box File Picker'),
'phpClassName' => 'BoxPickerAPI',
],
'one_drive' => [
'name' => t('OneDrive'),
'phpClassName' => 'OneDriveAPI',
],
'example' => [
'name' => t('Example'),
'phpClassName' => 'Example',
],
];
}
/**
* Implements hook_theme().
*/
function file_chooser_field_theme() {
return [
'file_chooser_field' => [
'variables' => [
'label' => NULL,
'class' => NULL,
'attributes' => [],
],
],
];
}
/**
* Preprocess function for the file-chooser-field
*/
function file_chooser_field_preprocess_file_chooser_field(&$vars) {
if (count($vars['attributes'])) {
foreach ($vars['attributes'] as $data => $value) {
if ($data == "plugin") {
$value = explode('\\', $value);
$value = end($value);
$data_attributes[] = ' data-' . $data . '=' . $value . '';
}
else {
$data_attributes[] = ' data-' . $data . '="' . $value . '"';
}
$vars['data_attributes'] = join(" ", $data_attributes);
}
}
}
/**
* Implements hook_library_info_build().
*/
function file_chooser_field_library_info_build() {
$libraries = [];
if (Drupal::moduleHandler()->moduleExists('file_chooser_field')) {
$config = \Drupal::config('file_chooser_field.settings');
$libraries['file_chooser_field.onedrive'] = [
'js' => [
'https://js.live.net/v5.0/OneDrive.js' => [
'type' => 'external',
'minified' => TRUE,
'attributes' => [
'id' => 'onedrive-js',
'client-id' => $config->get('onedrive_app_id'),
],
],
],
];
$libraries['file_chooser_field.dropbox'] = [
'js' => [
'https://www.dropbox.com/static/api/2/dropins.js' => [
'type' => 'external',
'minified' => TRUE,
'attributes' => [
'id' => 'dropboxjs',
'data-app-key' => $config->get('dropbox_app_key'),
],
],
],
];
}
return $libraries;
}
/**
* Implements hook_file_chooser_field_plugins_alter().
*/
function hook_file_chooser_field_plugins_alter(&$plugins) {
// Alter File Chooser Field plugins.
}
/**
* Implements hook_file_chooser_field_download().
*/
function hook_file_chooser_field_download($phpClassName, $remote_file, $local_file) {
// This could be used to track file downloades.
// @todo add better description.
}