This repository has been archived by the owner on Jan 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdropzonejs.module
107 lines (93 loc) · 2.74 KB
/
dropzonejs.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
<?php
/**
* @file
* Contains dropzonejs.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function dropzonejs_help($route_name, RouteMatchInterface $route_match) {
$output = '';
switch ($route_name) {
// Main module help for the dropzonejs module.
case 'help.page.dropzonejs':
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('DropzoneJS') . '</p>';
default:
}
return $output;
}
/**
* Implements hook_theme().
*/
function dropzonejs_theme() {
return [
'dropzonejs' => [
'render element' => 'element',
],
];
}
/**
* Prepares variables for dropzone form element.
*
* Default template: dropzonejs.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: A render element representing the file.
*/
function template_preprocess_dropzonejs(array &$variables) {
$element = $variables['element'];
$variables['attributes'] = [];
if (isset($element['#id'])) {
$variables['attributes']['id'] = $element['#id'];
}
if (!empty($element['#attributes']['class'])) {
$variables['attributes']['class'] = (array) $element['#attributes']['class'];
}
$variables['dropzone_description'] = $element['#dropzone_description'];
$variables['or_text'] = t('or');
$variables['select_files_button_text'] = t('Select files');
$variables['uploaded_files'] = $element['uploaded_files'];
}
/**
* Implements hook_library_info_build().
*/
function dropzonejs_library_info_build() {
$libraries = [];
if (\Drupal::moduleHandler()->moduleExists('libraries')) {
$exif_path = libraries_get_path('exif-js') . '/exif.js';
}
else {
$exif_path = DRUPAL_ROOT . '/libraries/exif-js/exif.js';
}
if ($exif_found = file_exists($exif_path)) {
$libraries['exif-js'] = [
'title' => 'Exif',
'website' => 'https://github.com/exif-js/exif-js',
'version' => 'v2.3.0',
'license' => [
'name' => 'MIT',
'url' => 'https://github.com/exif-js/exif-js/blob/master/LICENSE.md',
'gpl-compatible' => TRUE,
],
'js' => [
'/libraries/exif-js/exif.js' => [],
],
];
}
return $libraries;
}
/**
* Implements hook_library_info_alter().
*/
function dropzonejs_library_info_alter(&$libraries, $extension) {
if ($extension == 'dropzonejs' && \Drupal::moduleHandler()->moduleExists('libraries')) {
$libraries['dropzonejs']['js'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.js' => []];
$libraries['dropzonejs']['css']['component'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.css' => []];
if ($exif_path = libraries_get_path('exif-js')) {
$libraries['exif-js']['js'] = ['/' . $exif_path . '/exif.js' => []];
}
}
}