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.
If you have a "load" callback with some PHP Library, the PHP for the associated library isn't loaded until after the "load" callback is invoked. Having the files load before the callback is invoked allows you to make use of the Libraries PHP files within the callback itself.
Comment | File | Size | Author |
---|---|---|---|
#12 | 1321372_0-commit.patch | 12.51 KB | tstoeckler |
#10 | 1321372.patch | 11.59 KB | RobLoach |
#8 | 1321372.patch | 11.58 KB | RobLoach |
#3 | libraryspreloadpostload.patch | 2.22 KB | RobLoach |
loadfilesbeforecallback.patch | 536 bytes | RobLoach | |
Comments
Comment #1
RobLoachExample from Symfony...
With the patch applied, since the PHP files are loaded before the invoke is made, we can use the ClassLoader.
Comment #2
tstoecklerHmm... that makes sense. We actually want both, though. We don't do that yet, but a use-case for a 'pre-load' callback is turning filepaths like "jquery-[version]-min.js" into the proper names so they can be loaded. So this is actually a feature request, however a very valid one.
Comment #3
RobLoach"pre-load" and "post-load" maybe?
Comment #5
RobLoachMaybe "load" and "loaded"?
Comment #6
tstoecklerThat should probably come first.
That's not really correct. 'loaded' currently counts the number of loaded files, so
if ($library['loaded']) {}<\code> works, but it's not really a flag. Maybe we can just leave out the comment. :)
This looks really good already. We need to update the hook_libraries_info() documentation, though, and we need some tests for this. The callbacks are already tested in general so we just need to adapt the existing tests.
Comment #7
tstoeckler"pre-load" and "post-load" is seld-documenting and is inline with "pre-detect" and "post-detect", so let's go with that.
Comment #8
RobLoachSounds good... I fixed up the tests.
Comment #9
tstoecklerThanks very much for the patch. That was exactly what I was looking for. Below are some nitpicks, but they are really minor. And the tests show that this works as expected. I'll commit this in the next few days, and unless you want to roll another patch (which would be even more awesome) I'll fix the stuff below pre-commit.
To be more inline with the other groups, that should be something like: "At this point the library contains a 'loaded' key, which contains the number of files that were loaded."
And below: Library -> library.
And below: That should be "Pre-load and post-load callbacks ..."
Comment #10
RobLoachComment #11
tstoecklerThanks for the reroll. Below are some very minor nitpicks. I'm still marking RTBC, though, because (unless you'd like to re-roll again, which would be awesome, of course), I'd happily fix that prior to commit. If I weren't so terribly tired right now, I'd go ahead and commit it right now. I hope to get to that beginning of next week, though.
"loaded" -> 'loaded', also I think the first line wraps early.
"... only the pre-load AND POST-LOAD callback groupS ..."
Comment #12
tstoecklerI did some minor documentation fixes pre-commit, and then committed this. Patch is attached.
Thanks again!
http://drupal.org/commitlog/commit/10030/3db1b3ed803d00a4633096fa43faafb...