interface LibraryDiscoveryInterface (View source)

Discovers information for asset (CSS/JavaScript) libraries.

Library information is statically cached. Libraries are keyed by extension for several reasons:

  • Libraries are not unique. Multiple extensions might ship with the same library in a different version or variant. This registry cannot (and does not attempt to) prevent library conflicts.
  • Extensions implementing and thereby depending on a library that is registered by another extension can only rely on that extension's library.
  • Two (or more) extensions can still register the same library and use it without conflicts in case the libraries are loaded on certain pages only.

Methods

array
getLibrariesByExtension(string $extension)

Gets all libraries defined by an extension.

array|false
getLibraryByName(string $extension, string $name)

Gets a single library defined by an extension by name.

clearCachedDefinitions()

Clears static and persistent library definition caches.

Details

array getLibrariesByExtension(string $extension)

Gets all libraries defined by an extension.

Parameters

string $extension

The name of the extension that registered a library.

Return Value

array

An associative array of libraries registered by $extension is returned (which may be empty).

See also

\Drupal\Core\Asset\self::getLibraryByName()

array|false getLibraryByName(string $extension, string $name)

Gets a single library defined by an extension by name.

Parameters

string $extension

The name of the extension that registered a library.

string $name

The name of a registered library to retrieve.

Return Value

array|false

The definition of the requested library, if $name was passed and it exists, otherwise FALSE.

clearCachedDefinitions()

Clears static and persistent library definition caches.