diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 03b458f5e5..af30e3ba14 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php @@ -102,7 +102,7 @@ public function buildByExtension($extension) { $libraries = $this->applyLibrariesOverride($libraries, $extension); foreach ($libraries as $id => &$library) { - if (!isset($library['js']) && !isset($library['css']) && !isset($library['drupalSettings'])) { + if (!isset($library['js']) && !isset($library['css']) && !isset($library['drupalSettings']) && !isset($library['dependencies'])) { throw new IncompleteLibraryDefinitionException(sprintf("Incomplete library definition for definition '%s' in extension '%s'", $id, $extension)); } $library += ['dependencies' => [], 'js' => [], 'css' => []]; diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index ff643b000e..d377313b99 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -171,6 +171,25 @@ public function testInvalidLibrariesFile() { $this->libraryDiscoveryParser->buildByExtension('invalid_file'); } + /** + * Tests that an exception is thrown when no CSS/JS/setting is specified. + * + * @covers ::buildByExtension + */ + public function testBuildByExtensionWithOnlyDependencies() { + $this->moduleHandler->expects($this->atLeastOnce()) + ->method('moduleExists') + ->with('example_module_only_dependencies') + ->will($this->returnValue(TRUE)); + + $path = __DIR__ . '/library_test_files'; + $path = substr($path, strlen($this->root) + 1); + $this->libraryDiscoveryParser->setPaths('module', 'example_module_only_dependencies', $path); + + $libraries = $this->libraryDiscoveryParser->buildByExtension('example_module_only_dependencies'); + $this->assertArrayHasKey('example', $libraries); + } + /** * Tests that an exception is thrown when no CSS/JS/setting is specified. * diff --git a/core/tests/Drupal/Tests/Core/Asset/library_test_files/example_module_only_dependencies.libraries.yml b/core/tests/Drupal/Tests/Core/Asset/library_test_files/example_module_only_dependencies.libraries.yml new file mode 100644 index 0000000000..371d6ad810 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/example_module_only_dependencies.libraries.yml @@ -0,0 +1,2 @@ +example: + dependencies: { }