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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler’s picture

Well, 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

pillarsdotnet’s picture

I read the above and immediately thought:

  1. No problem; use a regular expression.
  2. Now you've got two problems.

But seriously, couldn't you allow a regex to convert the @version and @variant into a filename?

sun’s picture

tstoeckler’s picture

Status: Active » Needs review
FileSize
6.36 KB

Now 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)

tstoeckler’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev

Wrong branch...

tstoeckler’s picture

Same patch.

sun’s picture

+++ b/libraries.api.php
@@ -164,8 +164,16 @@
+ *       The following pre-load callbacks are available for all libraries:
+ *       - libaries_replace_filenames: Use this callback if your library files
+ *         have version- or variant-dependant filenames. The callback replaces
+ *         all occurences of '!version' in filenames with the detected library
+ *         version and all occurences of '!variant' with the variant.

Per 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.

sun’s picture

Title: Support version- and variant-dependent filenames. » Support version- and variant-dependent filenames

FYI: Interesting tidbit; the commit that introduced CDN support for jquery_update module:
http://drupalcode.org/project/jquery_update.git/blobdiff/8a3a09fe9cfd231...

Pol’s picture

Issue summary: View changes

FYI: You can use external libraries from a CDN using Libraries API CDN that integrates itself with Libraries API.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: -D7 stable release blocker +Needs reroll

The 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.