Needs work
Project:
Drupal core
Version:
main
Component:
asset library system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
2 Apr 2014 at 11:40 UTC
Updated:
5 Jun 2025 at 10:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
lussolucaComment #2
dawehnerI guess we also want to add this method to the interface?
Comment #3
lussolucaYes, I've only modified the class to see if this feature request made sense. I reattach the patch with both the class and the interface.
Comment #4
dawehnerIs there any usecase for this directly in core?
Comment #5
lussolucaIf a module want to use library API to manage external js libraries it needs a way to check if all required assets are present into /libraries folder. This check could be done into .install file but if different modules use this technique we'll have a lot of duplicated code. For me it make sense to have an API to check the existence of those files.
Comment #6
andypost+1, useful method. Just needs tests
Maybe
isLibraryValid()better?Comment #7
nod_I'm not sure how much we need this but at least
+ $parts = explode('/', $dependency);Needs to be
+ $parts = explode('/', $dependency, 2);To follow what's in core.
Comment #8
lussolucaNew patch with corrections in #6 and #7 and a simple test (not sure if enough).
Comment #9
lussolucaComment #11
wim leers#2355639: When files referenced in /core/modules/file/file.libraries.yml we should test that file actually exists was marked as a duplicate of this issue.
Comment #12
theodorosploumisWhat if the libraries are not under
DRUPAL_ROOT/librariesfolder but underDRUPAL_ROOT/profiles/PROFILE_NAME/libraries? The verification will fail. Probably we need to include all these libraries paths when doing the condition. Such paths are:Comment #13
wim leersYour description matches the Drupal 7 Libraries API. That's not what this is.
Comment #22
geaseWhy cannot we remove the condition https://git.drupalcode.org/project/drupal/-/blob/9.2.x/core/lib/Drupal/C...?
If LibrariesDirectoryFileFinder->find() returns FALSE, that means js file is missing, path in library definition is not changed, so it's still pointing to the missing file, and there's no hint that file is missing. If we put there FALSE instead, it would be obvious that the file is missing, and won't (as far as I've basically checked) break js on page more than missing file does.
Comment #25
anybodyStill this would be very very helpful as each module using a library now copies the logic to verify it is present.
Comment #29
grimreaperHi,
Regarding patch from comment 8, when looking for dependencies:
I think it should return FALSE as soon as a dependency is not satisfied.
Comment #30
grimreaperAnd also before the dependencies, as soon as file is not found it should return FALSE.
Comment #32
grimreaperMR created from patch 8 + my suggestion.
Test not copied because a test file with the same name exists now in Core.