Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / dropzonejs / dropzonejs.module
1 <?php
2
3 /**
4  * @file
5  * Contains dropzonejs.module.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9
10 /**
11  * Implements hook_help().
12  */
13 function dropzonejs_help($route_name, RouteMatchInterface $route_match) {
14   $output = '';
15   switch ($route_name) {
16     // Main module help for the dropzonejs module.
17     case 'help.page.dropzonejs':
18       $output .= '<h3>' . t('About') . '</h3>';
19       $output .= '<p>' . t('DropzoneJS') . '</p>';
20     default:
21   }
22   return $output;
23 }
24
25 /**
26  * Implements hook_theme().
27  */
28 function dropzonejs_theme() {
29   return [
30     'dropzonejs' => [
31       'render element' => 'element',
32     ],
33   ];
34 }
35
36 /**
37  * Prepares variables for dropzone form element.
38  *
39  * Default template: dropzonejs.html.twig.
40  *
41  * @param array $variables
42  *   An associative array containing:
43  *   - element: A render element representing the file.
44  */
45 function template_preprocess_dropzonejs(array &$variables) {
46   $element = $variables['element'];
47
48   $variables['attributes'] = [];
49   if (isset($element['#id'])) {
50     $variables['attributes']['id'] = $element['#id'];
51   }
52   if (!empty($element['#attributes']['class'])) {
53     $variables['attributes']['class'] = (array) $element['#attributes']['class'];
54   }
55
56   $variables['dropzone_description'] = $element['#dropzone_description'];
57   $variables['or_text'] = t('or');
58   $variables['select_files_button_text'] = t('Select files');
59   $variables['uploaded_files'] = $element['uploaded_files'];
60 }
61
62 /**
63  * Implements hook_library_info_build().
64  */
65 function dropzonejs_library_info_build() {
66   $libraries = [];
67
68   if (\Drupal::moduleHandler()->moduleExists('libraries')) {
69     $exif_path = libraries_get_path('exif-js') . '/exif.js';
70   }
71   else {
72     $exif_path = DRUPAL_ROOT . '/libraries/exif-js/exif.js';
73   }
74
75   if ($exif_found = file_exists($exif_path)) {
76     $libraries['exif-js'] = [
77       'title' => 'Exif',
78       'website' => 'https://github.com/exif-js/exif-js',
79       'version' => 'v2.3.0',
80       'license' => [
81         'name' => 'MIT',
82         'url' => 'https://github.com/exif-js/exif-js/blob/master/LICENSE.md',
83         'gpl-compatible' => TRUE,
84       ],
85       'js' => [
86         '/libraries/exif-js/exif.js' => [],
87       ],
88     ];
89
90   }
91
92   return $libraries;
93 }
94
95 /**
96  * Implements hook_library_info_alter().
97  */
98 function dropzonejs_library_info_alter(&$libraries, $extension) {
99   if ($extension == 'dropzonejs' && \Drupal::moduleHandler()->moduleExists('libraries')) {
100     $libraries['dropzonejs']['js'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.js' => []];
101     $libraries['dropzonejs']['css']['component'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.css' => []];
102
103     if ($exif_path = libraries_get_path('exif-js')) {
104       $libraries['exif-js']['js'] = ['/' . $exif_path . '/exif.js' => []];
105     }
106   }
107 }