Skip to content
Snippets Groups Projects
Commit 164a0ce4 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Issue #3295283 by heddn: Installation not working with Dropzone 6

parent 05bcb0f1
Branches
Tags
1 merge request!10Resolve #3295283 "Installation not working"
Pipeline #107378 passed with warnings
......@@ -53,14 +53,27 @@ variables:
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
OPT_IN_TEST_MAX_PHP: 1
DROPZONE_VERSION: v5.9.3
.composer-base:
after_script:
- mkdir $_WEB_ROOT/libraries
- cd $_WEB_ROOT/libraries
- curl https://codeload.github.com/enyo/dropzone/tar.gz/v5.5.0 --output dropzone.tar.gz --silent
- tar xzf dropzone.tar.gz
- mv dropzone-5.5.0 dropzone
- curl -L https://github.com/dropzone/dropzone/releases/download/$DROPZONE_VERSION/dist.zip -o dropzone.zip --silent
- unzip dropzone.zip
- mv dist dropzone
composer (dropzone 6):
extends: .composer-base
variables:
DROPZONE_VERSION: v6.0.0-beta.2
phpunit (dropzone 6):
extends: phpunit
needs:
- "composer (dropzone 6)"
variables:
DROPZONE_VERSION: v6.0.0-beta2
###################################################################################
#
......
......@@ -7,52 +7,52 @@ This is the Drupal integration for [DropzoneJS](http://www.dropzonejs.com/).
#### The non-composer way
1. Download this module
2. [Download DropzoneJS](https://github.com/enyo/dropzone) and place it in the
libraries folder
2. [Download DropzoneJS](https://github.com/dropzone/dropzone), use the latest
dist.zip for either Dropzone 5 or 6 and put it in a libraries/dropzone folder
so that you have libraries/dropzone/dropzone-min.js
3. Install dropzonejs the [usual way](https://www.drupal.org/docs/extending-drupal/installing-drupal-modules)
4. Remove "test" folder from libraries folder as it could constitute a
security risk to your site. See http://drupal.org/node/1189632 for more info.
You will now have a dropzonejs element at your disposal.
#### The composer way 1
#### The composer way
Run `composer require wikimedia/composer-merge-plugin`
This assumes that the type:drupal-library is set up to be installed in
web/libraries.
Update the root `composer.json` file. For example:
Add a custom package to the root `composer.json` file. Its `repositories` key
looks like the following. Adjust version numbers according to current release.
Dropzone 5:
```
"extra": {
"merge-plugin": {
"include": [
"web/modules/contrib/dropzonejs/composer.libraries.json"
]
"repositories": [
...
{
"type": "package",
"package": {
"name": "enyo/dropzone",
"version": "5.9.3",
"type": "drupal-library",
"dist": {
"url": "https://github.com/dropzone/dropzone/releases/download/v5.9.3/dist.zip",
"type": "zip"
}
}
}
]
```
Run `composer require drupal/dropzonejs enyo/dropzone`, the DropzoneJS library will be
installed to the `libraries` folder automatically.
#### The composer way 2
Add a custom package to the root `composer.json` file. Its `repositories` key
looks like the following.
Dropzone 5:
```
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
...
{
"type": "package",
"package": {
"name": "enyo/dropzone",
"version": "5.7.1",
"version": "6.0.0-beta2",
"type": "drupal-library",
"dist": {
"url": "https://github.com/enyo/dropzone/archive/v5.7.1.zip",
"url": "https://github.com/dropzone/dropzone/releases/download/v6.0.0-beta2/dist.zip",
"type": "zip"
}
}
......@@ -63,6 +63,25 @@ looks like the following.
Run `composer require drupal/dropzonejs enyo/dropzone`, the DropzoneJS library
will be installed to the `libraries` folder automatically as well.
To also install exif-js for optional client-resize, define another repository.
```
{
"type": "package",
"package": {
"name": "exif-js/exif-js",
"version": "v2.3.0",
"type": "drupal-library",
"dist": {
"type": "zip",
"url": "https://github.com/exif-js/exif-js/archive/refs/tags/v2.3.0.zip",
}
}
},
```
And require it with `composer require exif-js/exif-js`
### Future plans:
- A dropzonejs field widget.
- Handling already uploaded files.
......
......@@ -5,6 +5,8 @@
* Install, update and uninstall functions for the dropzonejs module.
*/
use Drupal\Core\Asset\LibraryDiscoveryInterface;
/**
* Implements hook_requirements().
*/
......@@ -12,37 +14,34 @@ function dropzonejs_requirements($phase) {
$requirements = [];
// @todo Remove this conditional structure in favor of using the libraries
// directory file finder service when Drupal 8.9 is the minimum supported
// version of core.
if (\Drupal::hasService('library.libraries_directory_file_finder')) {
/** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */
$library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
$library_found = (bool) $library_file_finder->find('dropzone/dist/min/dropzone.min.js');
}
else {
$path = DRUPAL_ROOT . '/libraries/dropzone/dist/min/dropzone.min.js';
if (\Drupal::moduleHandler()->moduleExists('libraries')) {
$path = libraries_get_path('dropzone') . '/dist/min/dropzone.min.js';
}
// Is the library found in the root libraries path.
$library_found = file_exists($path);
// If library is not found, then look in the current profile libraries path.
if (!$library_found) {
$profile_path = \Drupal::service('extension.list.profile')->getPath(\Drupal::installProfile());
$profile_path .= '/libraries/dropzone/dist/min/dropzone.min.js';
// Is the library found in the current profile libraries path.
$library_found = file_exists($profile_path);
$js_candidates = [
'dropzone/dropzone-min.js',
'dropzone/dropzone.min.js',
'dropzone/min/dropzone.min.js',
'dropzone/dist/min/dropzone-min.js',
];
$js_path = NULL;
foreach ($js_candidates as $js_candidate) {
if ($js_path = $library_file_finder->find($js_candidate)) {
break;
}
}
if (!$library_found) {
if ($js_path) {
$requirements['dropzonejs_library'] = [
'title' => t('Dropzone library found'),
'description' => t('Library location: @js_path', ['@js_path' => $js_path]),
'severity' => REQUIREMENT_OK,
];
}
else {
$requirements['dropzonejs_library'] = [
'title' => t('Dropzone library missing'),
'description' => t('Dropzonejs requires the dropzone.min.js library.
Download it (https://github.com/enyo/dropzone) and place it in the
Download it (https://github.com/dropzone/dropzone) and place it in the
libraries folder (/libraries)'),
'severity' => REQUIREMENT_ERROR,
];
......
......@@ -7,10 +7,10 @@ dropzonejs:
url: https://github.com/enyo/dropzone/blob/master/LICENSE
gpl-compatible: true
js:
/libraries/dropzone/dist/min/dropzone.min.js: { minified: true }
/libraries/dropzone/dropzone-min.js: { minified: true }
css:
component:
/libraries/dropzone/dist/min/dropzone.min.css: { minified: true }
/libraries/dropzone/dropzone.css: { minified: true }
widget:
version: VERSION
css:
......
......@@ -72,20 +72,9 @@ function template_preprocess_dropzonejs(array &$variables) {
function dropzonejs_library_info_build() {
$libraries = [];
// @todo Remove this conditional structure in favor of using the libraries
// directory file finder service when Drupal 8.9 is the minimum supported
// version of core.
if (\Drupal::hasService('library.libraries_directory_file_finder')) {
/** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */
$library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
$exif_path = $library_file_finder->find('exif-js/exif.js');
}
elseif (\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_path && file_exists($exif_path)) {
$libraries['exif-js'] = [
......@@ -111,12 +100,33 @@ function dropzonejs_library_info_build() {
* 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 ($extension !== 'dropzonejs') {
return;
}
/** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */
$library_file_finder = \Drupal::service('library.libraries_directory_file_finder');
$js_candidates = [
'dropzone/dropzone-min.js',
'dropzone/dropzone.min.js',
'dropzone/min/dropzone.min.js',
'dropzone/dist/min/dropzone.min.js',
];
foreach ($js_candidates as $js_candidate) {
if ($js_min_path = $library_file_finder->find($js_candidate)) {
$libraries['dropzonejs']['js'] = ['/' . $js_min_path => []];
}
}
if ($exif_path = libraries_get_path('exif-js')) {
$libraries['exif-js']['js'] = ['/' . $exif_path . '/exif.js' => []];
$css_candidates = [
'dropzone/dropzone.css',
'dropzone/min/dropzone.min.css',
'dropzone/dist/min/dropzone.min.css',
];
foreach ($css_candidates as $css_candidate) {
if ($css_path = $library_file_finder->find($css_candidate)) {
$libraries['dropzonejs']['css']['component'] = ['/' . $css_path => []];
}
}
}
......
......@@ -57,9 +57,11 @@ class DropzoneJsElementTest extends KernelTestBase {
$this->assertNotEmpty($this->xpath("$xpath_base/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]"));
// Upload files path.
$this->assertNotEmpty($this->xpath("$xpath_base/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]"));
// Js is attached.
$this->assertNotEmpty($this->xpath("//html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]"));
// Js is attached.
$new_js_path = $this->xpath("//html/body/script[contains(@src, 'libraries/dropzone/dropzone-min.js')]");
$old_js_path = $this->xpath("//html/body/script[contains(@src, 'libraries/dropzone/min/dropzone.min.js')]");
$this->assertTrue($new_js_path || $old_js_path);
$this->assertNotEmpty($this->xpath("//html/body/script[contains(@src, 'dropzonejs/js/dropzone.integration.js')]"));
}
......
<?php
namespace Drupal\Tests\dropzonejs\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
/**
* Tests related to the DropzoneJS requirements checks.
*
* @group dropzonejs
*/
class DropzoneRequirementsTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'file',
'user',
'dropzonejs',
];
/**
* Tests that the dropzonejs element appears.
*/
public function testRequirements() {
\Drupal::moduleHandler()->loadInclude('dropzonejs', 'install');
$requirements = dropzonejs_requirements('runtime');
$this->assertEquals(REQUIREMENT_OK, $requirements['dropzonejs_library']['severity']);
$this->assertEquals('Dropzone library found', (string) $requirements['dropzonejs_library']['title']);
$this->assertStringContainsString('Library location: libraries/dropzone/', (string) $requirements['dropzonejs_library']['description']);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment