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.
Looks like tests are failing with a whole bunch of You are not allowed to use libraries_load in #attached
errors.
Either something about drupal_process_attached()
has changed or perhaps there was an update to Libraries API. This needs to be investigated.
Comment | File | Size | Author |
---|---|---|---|
#9 | juicebox-remove_js_scope_option-2355253-9.patch | 4.31 KB | rjacobs |
Comments
Comment #1
rjacobs CreditAttribution: rjacobs commentedOk, the commit in the following core issue is what broke things:
#2350877: Deprecate/rename drupal_add_feed(), drupal_add_html_head(), drupal_add_html_head_link(), drupal_add_http_header(), and allow to be set declaratively in #attached
It tightens up
drupal_process_attached()
a bit and removes the ability to call arbitrary functions (like libraries_load) with it. There is continuing core discussion about all that and so any contrib fixes will be somewhat dependent on the resolutions to that (or a follow-up that spins off of it).Comment #2
rjacobs CreditAttribution: rjacobs commentedProper title
Comment #4
rjacobs CreditAttribution: rjacobs commentedI committed temporary a workaround for this that manually extracts the js data from the library details returned from libraries API. This should allow things to keep working until a proper fix is available vi the core/libraries APIs.
Comment #5
rjacobs CreditAttribution: rjacobs commentedNow that #2382533: Attach assets only via the asset library system has landed it's no longer possible to add JS via #attached, so my temporary workaround commit from #3 is no longer valid. So I need another temporary workaround, probably using an ad-hoc generated library definition, to make things work again. This would mean using hook_library_info_alter(), which probably won't be worth exploring too much until #2378737: Consider not executing hook_library_(info)_alter() *per* library, but once for all is resolved.
Comment #7
rjacobs CreditAttribution: rjacobs commentedI just committed another temporary workaround which should get things working again and allow test to pass.
Comment #8
rjacobs CreditAttribution: rjacobs commentedA new twist has surfaced, according to https://www.drupal.org/node/2412769 core is now adding all js to the footer by default. Given that we have inline js that depends on the library being already loaded this is a bit of a problem. Previously we manipulated the library's js "scope" parameter to allow the library to be loaded from either the header or the footer, with some special jQuery defer logic (for the gallery-specific inline js) to make things work for that latter. These recent core changes break all that.
To accommodate core I guess we need to abandon the previous conditional "scope" parameter, and use the new flag it offers to force a header addition. Once that's done I can explore whether-or-not it makes sense, or is even possible, to offer an option to switch the lib to the footer.
Comment #9
rjacobs CreditAttribution: rjacobs commentedHere's a patch implementing #8.
Comment #11
rjacobs CreditAttribution: rjacobs commentedAfter closing #2448159: Use Drupal.behaviors and Drupal.settings instead of inline js the module now uses Drupal.behaviors and Drupal.settings instead of inline js. This applies to both 7.x-2.x and 8.x-2.x so all the considerations related to the JS scope, etc. should be taken care of now in a robust way.
The missing pieces relate to the loading of external libraries and to what extent Libraries API will change and continue to be used by this module. Workarounds are in place now and we'll just have to see where things go with Libraries API before this can really be closed.
Comment #12
rjacobs CreditAttribution: rjacobs commentedI think the JS handling in core has settled now, so there is no longer a need for this issue.
The D8 version is currently integrating directly with Drupal core's APIs to load the library, which has been quite stable. This has been a workaround for the fact that the Libraries API module is not yet ready. The next step(s) are to start leveraging Libraries API, but that should be handled in another thread.