Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem
Files like jquery-1.4.3.min.js contain the the version and/or variant in their filename. Because the declaration in hook_libraries_info() is (should be) static, there is no way to tell Libraries API to load that file.
Comment | File | Size | Author |
---|---|---|---|
#6 | 964986-4-libraries-replace-filenames.patch | 6.36 KB | tstoeckler |
Comments
Comment #1
tstoecklerWell, the easy way out would be to define a @version and a @variant placeholder, which could be used in filenames, and which would be automatically replaced by Libraries API.
There's 2 reasons, that's not enough, though:
1. Where does it end? Can filenames differ depending on their location (local and external/hosted versions)? Can they contain a date (e.g. the day that version was released)? In the end we need something pluggable.
2. The above fails already when e.g. the version is 1.4.3, but the filename is example-1-4-3.js
Comment #2
pillarsdotnet CreditAttribution: pillarsdotnet commentedI read the above and immediately thought:
But seriously, couldn't you allow a regex to convert the @version and @variant into a filename?
Comment #3
sunComment #4
tstoecklerNow that we have callbacks, this shouldn't be too hard.
This is related to the whole file traversing debate though, see #1224838: Fix the inconsistency between filenames as array keys and array values for example.
I didn't want to go into that here, so I just do
foreach($files as $filename => $options)
Comment #5
tstoecklerWrong branch...
Comment #6
tstoecklerSame patch.
Comment #7
sunPer docs, this callback is invoked after the library has been detected. However, to detect a library with version or variant identifiers in its filename in the first place, the filename info needs to be adjusted in the pre-detect callback already.
I'm not sure whether this additional callback and automated replacement makes sense. Do we have a concrete use-case for this?
This issue mentions jQuery, but for that, we invented the pre-detect callback already, I think.
Comment #8
sunFYI: Interesting tidbit; the commit that introduced CDN support for jquery_update module:
http://drupalcode.org/project/jquery_update.git/blobdiff/8a3a09fe9cfd231...
Comment #9
PolFYI: You can use external libraries from a CDN using Libraries API CDN that integrates itself with Libraries API.
Comment #10
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 7 year old patch in #6 does not apply to the latest libraries 7.x-2.x-dev and if still applicable needs a reroll.