|Issue tags:||D7 stable release blocker|
While individual JS and CSS files can already be external (@see #1023274: Decide on whether or not to support 'inline' and 'settings' types for CSS/JS), for Libraries API to consider a library installed/existant/available there must be a corresponding subdirectory in the sites/all/libraries directory for the library.
This directory is not only completely worthless for libraries that are hosted externally, but it is also cumbersome (and a bit strange) to ask the user to create that directory each time and it sort of defeats the purpose of an external library in the first place.
- Whether a library is externally or locally loaded does not constitute a variant. The file, for instance jquery.js, is exactly the same, only its location is different. The minified version, jquery.min.js, is a different variant, but just the same you can load that same file locally or externally.
- Especially for one-file JS libraries, it is often a matter of personal taste (network latency, vs. bandwidth, effort, etc.) whether a library is downloaded to the server or used externally. If it is available locally, that constitutes the administrator's decision, so we should prefer local availability, but also provide an easy fallback mechanism for the external location.
Instead of hardcoding the
libraries_get_path() call in
libraries_detect(), provide a 'path callback' key for libraries, which defaults to
libraries_get_path() and which populates the 'path' key. That way libraries can provide their own business logic for where they are located under which circumstances.
Simple external libraries simply populate the 'path' key upfront and no detection takes place. The specified path is assumed to exist.
To accomodate the use-case in 2. above, libraries_get_path() now takes an optional
$fallback parameter. If that is specified, libraries_get_path() returns that instead of FALSE if the library isn't found locally.
function libraries_get_path($name, $base_path = NULL)=>
$library['path callback'] = 'libraries_get_path'