Problem/Motivation
There is a particular use case that the current hook_library_info_alter()
code does not support. Say module A wants to add a library that depends on the core core/drupal.ajax
library. This core library is used in many places, but module A wants its code to always run if that core library is used. One could implement hook_library_info_alter()
, and alter the core ajax library definition to depend on module A's library, but then module A's code would run first, which might not be desirable.
This is technically possible using a combination of hook_css_alter()
, and hook_js_alter()
, but one must then manually specify every js and css file, and also parse through fully-qualified asset paths to determine which libraries are included.
Proposed resolution
Add hook_library_alter()
for modules and themes to have the opportunity to add additional libraries.
Remaining tasks
User interface changes
API changes
Addition of a new hook.
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#2 | 2785815-02.patch | 6.13 KB | jhedstrom |
Comments
Comment #2
jhedstromHere's an initial approach.
Comment #3
cilefen CreditAttribution: cilefen commentedComment #4
SchnWalter CreditAttribution: SchnWalter commentedI believe that
hook_library_alter()
isn't a good name for this hook since it just receives a list of strings that represent namespaced libraries like `core/normalize` and `bartik/global-styling`.One would think that `hook_library_alter` would be used to change a library, not change the list of libraries to load.
Comment #5
SchnWalter CreditAttribution: SchnWalter commentedjhedstrom, have you tried replacing the library using libraries_override, see this change log: Libraries can now be overridden and extended by themes and Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme > Overriding and extending libraries
I would suggest that you try that, and if it works, you can resolve this as
Closed (won't Fix)