Problem/Motivation
Quite a few contrib modules (for example dropzonejs, Content Browser, Select2) have an optional dependency on the Libraries module. They do this do allow the library to placed in locations other than DRUPAL_ROOT/libraries/
. For example, on drupal.org distributions wishing to including third party libraries have to use drush make. This places the library in the install profile directory.
Therefore you see a lot of code like:
/**
* 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)) {
One major problem with this is that libraries_get_path()
is deprecated and supposed to be removed in the Drupal 8 (!!!) version of the Libraries module. This has not come to pass but essentially all the modules that are doing something similar to the dropzonejs example above are only using the Libraries module for 1 reason and thats because it searches a defined set up of paths for libraries. This depends on two of its methods - libraries_get_path()
and libraries_get_libraries()
. Both of these are deprecated with the message:
* @deprecated Will be removed before a stable Drupal 8 release. Please use the
* new library load and managment concepts described at:
* https://www.drupal.org/node/2170763
The link shows that the Libraries module doesn't really want to continue providing this type of functionality and instead was trying to be a registry and had far more expansive D8 ideas. It doesn't appear that these have borne fruit.
Proposed resolution
There's a lot of discussion about how Drupal should support modules and themes wanting to use other frontend libraries. See #2605130: Best practices for handling external libraries in Drupal 8 for instance.
This issue is not trying to solve the bigger problem.
The proposal here is to search the following paths:
- PATH/TO/INSTALL_PROFILE/libraries
- libraries
- PATH/TO/SITE/libraries
when we encounter a library path like /libraries/dropzone/dist/min/dropzone.min.js
. This will allow modules to drop Libraries module integration but maintain the support for third party libraries in multiple locations.
The above search locations are the same as libraries_get_libraries()
apart from sites/all/libraries has been removed - and I think the last location found wins so PATH/TO/SITE/libraries
> libraries
> PATH/TO/INSTALL_PROFILE/libraries
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
@todo - will need CR to do document the new functionality.