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.
Problem/Motivation
An entry in *.libraries.yml must contain either css
, js
, or drupalSettings
to be considered valid.
However, a library that only contains other libraries as dependencies is still useful.
Proposed resolution
Do not throw an exception when a library contains only other dependencies.
Remaining tasks
N/A
User interface changes
N/A
API changes
Not really? Adjusts the definition of IncompleteLibraryDefinitionException
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff_15-19.txt | 762 bytes | zrpnr |
#19 | 2905429-19.patch | 2.67 KB | zrpnr |
#15 | 2905429-15.patch | 2.61 KB | zrpnr |
#2 | 2905429-libraries-2-PASS.patch | 2.63 KB | tim.plunkett |
#2 | 2905429-libraries-2-FAIL.patch | 1.72 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #4
Wim Leers+1! I think this makes sense. We should also get @nod_'s thoughts though. I think we've considered this before at some point.
Well but this asset library does seem rather nonsensical, doesn't it? Shouldn't it at least have some dependency?
Comment #5
tstoecklerCan you provide an example of why this would be useful?
Comment #6
tim.plunkett#4
Yes, well a definition of:
is also valid. I followed that.
To fix all of them would be a BC break, but it'd be a switch from !isset to empty.
#5
In this case, there are multiple places I needed to add both outside_in and off_canvas libraries as #attached.
And then they switched s/outside_in/settings_tray, and I realized how many places that was.
And in the future, off_canvas will move from settings tray to core/misc, and I'd need to update again.
The idea was to make a single custom "library" that wrapped those two, making only one place that would need to be updated in the future.
Comment #7
Jacine+1. I ran into this today. Use case is:
- I have a library definition for each layout, e.g. one for a 50% / 50%, another for 75% 25%, etc.
- I also have a library definition that loads ALL of them, instead of having to do
attach_library()
20 times if you need them all (you might).Results in one
{{ attach_library('lala/layouts.all') }}
, being possible vs...{{ attach_library('lala/layouts.layout_1') }}
{{ attach_library('lala/layouts.layout_2') }}
{{ attach_library('lala/layouts.layout_3') }}
, etc.Thanks!
Comment #8
Wim LeersComment #9
catchDoes this need a change record?
Comment #10
xjmYeah, a small change record would be good. Otherwise this looks fine to me.
Comment #14
chrisolof CreditAttribution: chrisolof at Lima Solutions for CivicSolar, Inc. commentedThis would be useful. For now adding the
js: { }
does prevent the exception.My use case: Packaging up a collection of libraries into a single, meta library is a code and complexity reduction in my codebase. It doesn't necessarily need to add any files or settings of its own to be useful.
Comment #15
zrpnrI came across this issue when we were working on #2926155: Follow-up to #2809427: update from jQuery UI 1.11.4 to 1.12.1 forgot to list some new JS files in *.libraries.yml
One idea in that issue for de-tangling the dependencies of jQuery UI was to pull each dependent file out to its own asset library which could be selectively required by the other jQuery UI asset libraries. A single "collection" of these other smaller libraries would have been a convenient solution for maintaining BC while the actual files were shuffled around.
It looks like this issue just needed a change record and a re-roll for the patch (although it was still green). I ran the
LibraryDiscoveryParserTest
and tested this manually by creating a jQuery UI asset library that only depended on another new asset library.Comment #17
zrpnrAnother use case for this:
in 3067251 # 49
@xjm discussed an approach for a contrib module that would be just a dependency.
A contrib module could act as a placeholder for a soon-to-be-deprecated core library.
Modules could depend on a contrib asset library which in turn depends on a core asset library.
Once that core asset library is removed, the contrib library could provide the files instead, and the modules' dependency would be unchanged.
Comment #18
Wim LeersShouldn't this be
🤔Comment #19
zrpnrThat's correct, the other tests in this suite all
expectException
while this new test checks that no exception is thrown.I also changed the wording of the
testBuildByExtensionWithMissingInformation
comment since it didn't mention dependencies in the missing info it's checking.Comment #20
Wim LeersPerfect :)
Comment #21
Wim LeersNote this is perfectly cherry-pickable to
8.8.x
— no disruption.Comment #25
catchCommitted a80a479 and pushed to 9.0.x then cherry-picked back to 8.9.x and 8.8.x. Thanks!
Comment #27
kim.pepperI was a bit confused by the title of this change record. At first glance it read that libraries may contain only other libraries, which didn't make sense. Can I suggest:
Libraries may contain other libraries as dependencies