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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rjacobs’s picture

Ok, 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).

rjacobs’s picture

Title: Post beta1 (D8 core) tests currently failing » libraries_load can no longer be used in #attached

Proper title

  • rjacobs committed c34045c on 8.x-2.x
    Issue #2355253 by rjacobs: Add workaround for fact that libraries api...
rjacobs’s picture

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

rjacobs’s picture

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

  • rjacobs committed 6774187 on 8.x-2.x
    Issue #2355253 by rjacobs: New workaround for loading the library and...
rjacobs’s picture

I just committed another temporary workaround which should get things working again and allow test to pass.

rjacobs’s picture

Title: libraries_load can no longer be used in #attached » JS handeling in D8 core is constantly changing

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

rjacobs’s picture

Status: Active » Needs review
FileSize
4.31 KB

Here's a patch implementing #8.

  • rjacobs committed 757963c on 8.x-2.x
    Issue #2355253 by rjacobs: Remove js scope option that is no longer...
rjacobs’s picture

Status: Needs review » Active

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

rjacobs’s picture

Status: Active » Fixed

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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.