function AssetResolver::getLibrariesToLoad

Same name in other branches
  1. 9 core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::getLibrariesToLoad()
  2. 8.9.x core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::getLibrariesToLoad()
  3. 11.x core/lib/Drupal/Core/Asset/AssetResolver.php \Drupal\Core\Asset\AssetResolver::getLibrariesToLoad()

Returns the libraries that need to be loaded.

For example, with core/a depending on core/c and core/b on core/d:

$assets = new AttachedAssets();
$assets->setLibraries([
    'core/a',
    'core/b',
    'core/c',
]);
$assets->setAlreadyLoadedLibraries([
    'core/c',
]);
$resolver->getLibrariesToLoad($assets) === [
    'core/a',
    'core/b',
    'core/d',
];

Parameters

\Drupal\Core\Asset\AttachedAssetsInterface $assets: The assets attached to the current response.

Return value

string[] A list of libraries and their dependencies, in the order they should be loaded, excluding any libraries that have already been loaded.

3 calls to AssetResolver::getLibrariesToLoad()
AssetResolver::getCssAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
AssetResolver::getJsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
AssetResolver::getJsSettingsAssets in core/lib/Drupal/Core/Asset/AssetResolver.php
Returns the JavaScript settings assets for this response's libraries.

File

core/lib/Drupal/Core/Asset/AssetResolver.php, line 104

Class

AssetResolver
The default asset resolver.

Namespace

Drupal\Core\Asset

Code

protected function getLibrariesToLoad(AttachedAssetsInterface $assets) {
    // 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()));
}

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