LibraryDependencyResolver::getMinimalRepresentativeSubset

public LibraryDependencyResolver::getMinimalRepresentativeSubset(array $libraries)

Gets the minimal representative subset of the given libraries.

A minimal representative subset means that any library in the given set of libraries that is a dependency of another library in the set, is removed.

Hence a minimal representative subset is the most compact representation possible of a set of libraries.

(Each asset library has dependencies and can therefore be seen as a tree. Hence the given list of libraries represent a forest. This function returns all roots of trees that are not a subtree of another tree in the forest.)

Parameters

string[] $libraries: A set of libraries.

Return value

string[] A representative subset of the given set of libraries.

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) {
  $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;
}
doc_Drupal
2016-10-29 09:23:05
Comments
Leave a Comment

Please login to continue.