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.
I think this is one of the last missing pieces in our API feature-wise.
Libraries can depend on other libraries. The most obvious example is the load of jQuery libraries that of course depend on jQuery. Or JQuery UI where each component (is that what they call it?) depends on different subsets of the core library.
This patch introduces a new $library['dependencies'] property. There are two ways to specify this property:
// This doesn't care which variant is used.
$library['dependencies'] = array('jquery');
// This loads the 'minified' variant of jquery.
$library['dependencies'] = array('jquery' => 'minified');
Comes with tests.
I also added a 'Dependencies' column to the output of drush libraries-list
.
Comment | File | Size | Author |
---|---|---|---|
#8 | 962214-5-libraries-dependencies.patch | 11.54 KB | tstoeckler |
#5 | 962214-5-libraries-dependencies.patch | 11.54 KB | tstoeckler |
#4 | 962214-4-libraries-dependencies.patch | 5.02 KB | tstoeckler |
libraries-dependencies.patch | 10.88 KB | tstoeckler | |
Comments
Comment #1
tstoecklerIn case we actually go with the proposed compatible declaration which supports both
'dependencies' => array($name)
and
'dependencies' => array($name => $variant)
we will want to make that consistent just like in #1023258: Make 'files' (and 'integration files') declarations consistent.
Hence, this is postponed on #958162: Allow groups of callbacks to be applied to libraries.
Comment #2
tstoecklerThis is no longer postponed.
For reference: The above doesn't quite make sense. A library should function regardless of its variant, i.e. if you depend on a specific variant you're doing something wrong. What is relevant, though, is the version of the library, so we should use that.
Comment #3
sunBasically, it's:
So, considering the PHP declaration first:
Ouch. Now I realize that dependencies are likely defined globally per library, so specifying a particular variant is more or less impossible.
Well, in that case, we could simply go ahead and take over what the module system does:
Comment #4
tstoecklerHere's a patch to get things rolling. No tests yet, and I also didn't test it manually, so statistically, it's probably broken. But could probably use some thoughts on the general idea.
Comment #5
tstoecklerNot true, the code above actually worked :).
Also, I'm beginning to really like our testing method (although LibrariesUnitTestCase appears in my dreams ever so often).
In short: Here's a patch with extensive tests. It (unit) tests the dependecy detection (mostly the version parsing) and the loading of dependencies separately. That's in some way duplicate, but they are different code paths (libraries_detect_dependencies() (better name?), and libraries_load()), so...
The actual code is almost (!!) identical to #4.
This is now actually "needs review".
Comment #6
tstoecklerOh, and a quick disclaimer:
It's so late here, that it's early, which probably means I went really short on code comments.
Comment #7
tstoecklerWrong branch for testing.
Comment #8
tstoecklerRe-uploading #5
Comment #9
sunThis looks very good. A test with a real world module would be lovely, but I'm not sure which module actively depends on multiple libraries that have a dependency between themselves on their own. (wow, that's mind-boggling ;)
Comment #10
tstoecklerI guess we'll find out if this works for real when jquery.module finally gets done. But that still depends on at least #964986: Support version- and variant-dependent filenames, if not others.
Comment #11
sunComment #12
tstoecklerMinor (!!!) nit: This should use single quotes.
I just looked through this patch and couldn't find anything (else) to complain about. Since it's been a while since I rolled this, I'm going to mark this RTBC. I'll give it a few days and then commit (with the small change above).
Comment #13
tstoecklerAlso super minor: This should probably be "Example" for consistency.
The time has come now. :)
Comment #14
tstoecklerCommitted #5 to 7.x-2.x with the two changes mentioned above.
http://drupal.org/commitlog/commit/10030/c60cfc3e3769bc172c1961da2606ba0...
Comment #15
tstoecklerJust a note that I realized that somehow the hunk which added this to the output of "drush libraries-list" got lost. I think that's actual a valuable addition (could be persuaded, though), so re-opening.
Comment #16
tstoecklerActually, no let's do that in a separate issue: #1268342: Clean-up drush libraries-list