function LibraryDiscoveryCollector::getLibraryDefinitions

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

Returns the library definitions for a given extension.

This also implements libraries-overrides for entire libraries that have been specified by the LibraryDiscoveryParser.

Parameters

string $extension: The name of the extension for which library definitions will be returned.

Return value

array The library definitions for $extension with overrides applied.

Throws

\Drupal\Core\Asset\Exception\InvalidLibrariesOverrideSpecificationException

1 call to LibraryDiscoveryCollector::getLibraryDefinitions()
LibraryDiscoveryCollector::resolveCacheMiss in core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php
Resolves a cache miss.

File

core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php, line 86

Class

LibraryDiscoveryCollector
A CacheCollector implementation for building library extension info.

Namespace

Drupal\Core\Asset

Code

protected function getLibraryDefinitions($extension) {
    $libraries = $this->discoveryParser
        ->buildByExtension($extension);
    foreach ($libraries as $name => $definition) {
        // Handle libraries that are marked for override or removal.
        // @see \Drupal\Core\Asset\LibraryDiscoveryParser::applyLibrariesOverride()
        if (isset($definition['override'])) {
            if ($definition['override'] === FALSE) {
                // Remove the library definition if FALSE is given.
                unset($libraries[$name]);
            }
            else {
                // Otherwise replace with existing library definition if it exists.
                // Throw an exception if it doesn't.
                list($replacement_extension, $replacement_name) = explode('/', $definition['override']);
                $replacement_definition = $this->get($replacement_extension);
                if (isset($replacement_definition[$replacement_name])) {
                    $libraries[$name] = $replacement_definition[$replacement_name];
                }
                else {
                    throw new InvalidLibrariesOverrideSpecificationException(sprintf('The specified library %s does not exist.', $definition['override']));
                }
            }
        }
        else {
            // If libraries are not overridden, then apply libraries-extend.
            $libraries[$name] = $this->applyLibrariesExtend($extension, $name, $definition);
        }
    }
    return $libraries;
}

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