You are here

public function LibraryDependencyResolver::getMinimalRepresentativeSubset in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset()
  2. 9 core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset()

File

core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php, line 81

Class

LibraryDependencyResolver
Resolves the dependencies of asset (CSS/JavaScript) libraries.

Namespace

Drupal\Core\Asset

Code

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($libraries, array_intersect($all_dependencies, $libraries)));
}