diff --git a/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryParser.php index 03b458f5e5e3b24988d3266b80902a11deb64abb..af30e3ba1497a04f8ae30b1591f715c5bab8465a 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 ff643b000e1798f72b8cf8383cf432b0519ef2c8..222537e268ae333557a10ec64a9026cb9253790d 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -172,7 +172,26 @@ public function testInvalidLibrariesFile() { } /** - * Tests that an exception is thrown when no CSS/JS/setting is specified. + * Tests that no exception is thrown when only dependencies are 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 with only the version property specified. * * @covers ::buildByExtension */ 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 0000000000000000000000000000000000000000..371d6ad81029f1040adbac0707428459828b459b --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Asset/library_test_files/example_module_only_dependencies.libraries.yml @@ -0,0 +1,2 @@ +example: + dependencies: { }