interface AssetLibraryInterface in Libraries API 8.3
Provides an interface for external asset libraries with a single library.
Asset is the generic term for CSS and JavaScript files.
In order to load assets of external libraries as part of a page request the assets must be registered with Drupal core's library system. Therefore, Libraries API makes all libraries that are required by the installed installation profile, modules, and themes available as core asset libraries with the identifier 'libraries/[machine_name]' where '[machine_name]' is the Libraries API machine name of the external library.
Thus, assuming that the external library 'flexslider' has been declared as a dependency, for example, it can be attached to a render array in the $build variable with the following code:
$build['#attached']['library'] = [
'libraries/flexslider',
];
In some cases an external library may contain multiple components, that should be loadable independently from each other. In this case, implement MultipleAssetLibraryInterface instead.
@todo Support loading of source or minified assets. @todo Document how library dependencies work.
Hierarchy
- interface \Drupal\libraries\ExternalLibrary\LibraryInterface; interface \Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface; interface \Drupal\libraries\ExternalLibrary\Dependency\DependentLibraryInterface
- interface \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryInterface
Expanded class hierarchy of AssetLibraryInterface
All classes that implement AssetLibraryInterface
See also
libraries_library_info_build()
\Drupal\libraries\ExternalLibrary\Asset\AssetLibraryTrait
\Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface
Related topics
File
- src/
ExternalLibrary/ Asset/ AssetLibraryInterface.php, line 42
Namespace
Drupal\libraries\ExternalLibrary\AssetView source
interface AssetLibraryInterface extends LibraryInterface, VersionedLibraryInterface, DependentLibraryInterface {
/**
* Returns a core asset library array structure for this library.
*
* @param \Drupal\libraries\ExternalLibrary\LibraryManagerInterface $library_manager
* The library manager that can be used to fetch dependencies.
*
* @return array
*
* @see \Drupal\libraries\ExternalLibrary\Asset\SingleAssetLibraryTrait
*
* @throws \Drupal\libraries\ExternalLibrary\Exception\InvalidLibraryDependencyException
*
* @todo Document the return value.
* @todo Reconsider passing the library manager.
*/
public function getAttachableAssetLibrary(LibraryManagerInterface $library_manager);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssetLibraryInterface:: |
public | function | Returns a core asset library array structure for this library. | 1 |
DependentLibraryInterface:: |
public | function | Returns the libraries dependencies, if any. | |
LibraryInterface:: |
public static | function | Creates an instance of the library from its definition. | 1 |
LibraryInterface:: |
public | function | Returns the ID of the library. | |
LibraryInterface:: |
public | function | Returns the library type of the library. | 1 |
VersionedLibraryInterface:: |
public | function | Gets the version of the library. | |
VersionedLibraryInterface:: |
public | function | Gets the version detector of this library using the detector factory. | |
VersionedLibraryInterface:: |
public | function | Sets the version of the library. |