function LibraryDependencyResolver::getMinimalRepresentativeSubset

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset()
  2. 10 core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset()
  3. 11.x core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php \Drupal\Core\Asset\LibraryDependencyResolver::getMinimalRepresentativeSubset()

Overrides LibraryDependencyResolverInterface::getMinimalRepresentativeSubset

File

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

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.');
    $minimal = [];
    // Determine each library's dependencies.
    $with_deps = [];
    foreach ($libraries as $library) {
        $with_deps[$library] = $this->getLibrariesWithDependencies([
            $library,
        ]);
    }
    foreach ($libraries as $library) {
        $exists = FALSE;
        foreach ($with_deps as $other_library => $dependencies) {
            if ($library == $other_library) {
                continue;
            }
            if (in_array($library, $dependencies)) {
                $exists = TRUE;
                break;
            }
        }
        if (!$exists) {
            $minimal[] = $library;
        }
    }
    return $minimal;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.