3 namespace Drupal\libraries\ExternalLibrary\Asset;
5 use Drupal\libraries\ExternalLibrary\Dependency\DependentLibraryInterface;
6 use Drupal\libraries\ExternalLibrary\LibraryInterface;
7 use Drupal\libraries\ExternalLibrary\LibraryManagerInterface;
8 use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface;
11 * Provides an interface for external asset libraries with a single library.
13 * Asset is the generic term for CSS and JavaScript files.
15 * In order to load assets of external libraries as part of a page request the
16 * assets must be registered with Drupal core's library system. Therefore,
17 * Libraries API makes all libraries that are required by the installed
18 * installation profile, modules, and themes available as core asset libraries
19 * with the identifier 'libraries/[machine_name]' where '[machine_name]' is
20 * the Libraries API machine name of the external library.
22 * Thus, assuming that the external library 'flexslider' has been declared as a
23 * dependency, for example, it can be attached to a render array in the $build
24 * variable with the following code:
26 * $build['#attached']['library'] = ['libraries/flexslider'];
29 * In some cases an external library may contain multiple components, that
30 * should be loadable independently from each other. In this case, implement
31 * MultipleAssetLibraryInterface instead.
33 * @see libraries_library_info_build()
34 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryTrait
35 * @see \Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface
37 * @todo Support loading of source or minified assets.
38 * @todo Document how library dependencies work.
42 interface AssetLibraryInterface extends
44 VersionedLibraryInterface,
45 DependentLibraryInterface
49 * Returns a core asset library array structure for this library.
51 * @param \Drupal\libraries\ExternalLibrary\LibraryManagerInterface $library_manager
52 * The library manager that can be used to fetch dependencies.
56 * @see \Drupal\libraries\ExternalLibrary\Asset\SingleAssetLibraryTrait
58 * @throws \Drupal\libraries\ExternalLibrary\Exception\InvalidLibraryDependencyException
60 * @todo Document the return value.
61 * @todo Reconsider passing the library manager.
63 public function getAttachableAssetLibrary(LibraryManagerInterface $library_manager);