getLibrariesWithDependencies example



  /** * {@inheritdoc} */
  public function getMinimalRepresentativeSubset(array $libraries) {
    assert(count($libraries) === count(array_unique($libraries)), '$libraries can\'t contain duplicate items.');

    // Determine each library's dependencies.     $all_dependencies = [];
    foreach ($libraries as $library) {
      $with_deps = $this->getLibrariesWithDependencies([$library]);
      // We don't need library itself listed in the dependencies.       $all_dependencies += array_diff($with_deps[$library]);
    }

    return array_values(array_diff($librariesarray_intersect($all_dependencies$libraries)));
  }

}
'test/no_deps_a', 'test/deps_c', 'test/nested_deps_b']['test/no_deps_a', 'test/no_deps_b', 'test/deps_c', 'test/deps_a', 'test/nested_deps_a', 'test/nested_deps_b']],
      [['test/nested_deps_b', 'test/deps_c', 'test/no_deps_c']['test/no_deps_a', 'test/deps_a', 'test/nested_deps_a', 'test/nested_deps_b', 'test/no_deps_b', 'test/deps_c', 'test/no_deps_c']],
    ];
  }

  /** * @covers ::getLibrariesWithDependencies * * @dataProvider providerTestGetLibrariesWithDependencies */
  public function testGetLibrariesWithDependencies(array $libraries, array $expected) {
    $this->assertEquals($expected$this->libraryDependencyResolver->getLibrariesWithDependencies($libraries));
  }

  /** * Provides test data for ::testGetMinimalRepresentativeSubset(). */
  public function providerTestGetMinimalRepresentativeSubset() {
    return [
      // Empty list of libraries.       [[][]],
      // Without dependencies.       [['test/no_deps_a']['test/no_deps_a']],
      [[
// The order of libraries passed in via assets can differ, so to reduce     // variation, first normalize the requested libraries to the minimal     // representative set before then expanding the list to include all     // dependencies.     // @see Drupal\FunctionalTests\Core\Asset\AssetOptimizationTestUmami     // @todo: https://www.drupal.org/project/drupal/issues/1945262     $libraries = $assets->getLibraries();
    if ($libraries) {
      $libraries = $this->libraryDependencyResolver->getMinimalRepresentativeSubset($libraries);
    }
    return array_diff(
      $this->libraryDependencyResolver->getLibrariesWithDependencies($libraries),
      $this->libraryDependencyResolver->getLibrariesWithDependencies($assets->getAlreadyLoadedLibraries())
    );
  }

  /** * {@inheritdoc} */
  public function getCssAssets(AttachedAssetsInterface $assets$optimize, LanguageInterface $language = NULL) {
    if (!isset($language)) {
      $language = $this->languageManager->getCurrentLanguage();
    }
    
Home | Imprint | This part of the site doesn't use cookies.