f79d5784ddeaa0566c9b443f97c7d79dac0c758a
[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_alter().
64  */
65 function dropzonejs_library_info_alter(&$libraries, $extension) {
66   if ($extension == 'dropzonejs' && \Drupal::moduleHandler()->moduleExists('libraries')) {
67     $libraries['dropzonejs']['js'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.js' => []];
68     $libraries['dropzonejs']['css']['component'] = ['/' . libraries_get_path('dropzone') . '/dist/min/dropzone.min.css' => []];
69   }
70 }