diff --git a/dropzonejs.libraries.yml b/dropzonejs.libraries.yml index 57d8ad2..a73667e 100644 --- a/dropzonejs.libraries.yml +++ b/dropzonejs.libraries.yml @@ -11,16 +11,6 @@ dropzonejs: css: component: /libraries/dropzone/dist/min/dropzone.min.css: {} -exif-js: - title: 'Exif' - website: https://github.com/exif-js/exif-js - version: v2.2.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: {} widget: version: VERSION css: diff --git a/dropzonejs.module b/dropzonejs.module index ba34542..a093863 100644 --- a/dropzonejs.module +++ b/dropzonejs.module @@ -60,6 +60,39 @@ function template_preprocess_dropzonejs(array &$variables) { } /** + * 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.2.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) { diff --git a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php index f96a98b..a12d955 100644 --- a/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php +++ b/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php @@ -376,25 +376,22 @@ class DropzoneJsEbWidget extends WidgetBase { ]; - if (\Drupal::moduleHandler()->moduleExists('libraries')) { - $exif_path = libraries_get_path('exif-js') . '/exif.js'; - } - else { - $exif_path = DRUPAL_ROOT . '/libraries/exif-js/exif.js'; - } - - // Is the library found in the root libraries path. - $exif_found = file_exists($exif_path); + $exif_found = \Drupal::service('library.discovery')->getLibraryByName('dropzonejs', 'exif-js'); $form['clientside_resize'] = [ '#type' => 'checkbox', '#title' => $this->t('Use client side resizing'), - '#default_value' => $exif_found ? $configuration['clientside_resize'] : FALSE, + '#default_value' => $configuration['clientside_resize'], ]; if (!$exif_found) { $form['clientside_resize']['#description'] = $this->t('Requires droopzone version v4.4.0 or higher and the exif library.', ['@exif' => 'https://github.com/exif-js/exif-js']); - $form['clientside_resize']['#disabled'] = TRUE; + + // We still want to provide a way to disable this if the library does not + // exist. + if ($configuration['clientside_resize'] == FALSE) { + $form['clientside_resize']['#disabled'] = TRUE; + } } $form['resize_width'] = [