3 namespace Drupal\libraries\ExternalLibrary\Asset;
5 use Drupal\libraries\ExternalLibrary\LibraryInterface;
6 use Drupal\libraries\ExternalLibrary\LibraryManagerInterface;
9 * Provides an interface for external asset libraries with multiple libraries.
11 * See SingleAssetLibraryInterface for more information on external asset
12 * libraries in general.
14 * In case an external asset library contains multiple components that should
15 * be loadable independently from each other, Libraries API registers each
16 * library component as a separate library in the core asset library system. The
17 * resulting core library identifier is
18 * 'libraries/[machine_name].[component_name]' where '[machine_name]' is the
19 * Libraries API machine name of the external library and '[component_name]' is
20 * the component name specified by the library definition.
22 * Thus, assuming that the external library 'bootstrap' has been declared as a
23 * dependency, for example, and it has 'button' and 'form' components, they can
24 * be attached to a render array in the $build variable with the following code:
26 * $build['#attached']['library'] = [
27 * 'libraries/bootstrap.button',
28 * 'libraries/bootstrap.form',
32 * @see \Drupal\libraries\ExternalLibrary\Asset\AssetLibraryInterface
34 * @todo Support loading of source or minified assets.
35 * @todo Document how library dependencies work.
37 interface MultipleAssetLibraryInterface extends LibraryInterface {
40 * Separates the library machine name from its component name.
42 * The period is chosen in alignment with core asset libraries, which are
43 * named, for example, 'core/jquery.once'.
45 const SEPARATOR = '.';
48 * Returns a core asset library array structure for this library.
50 * @param \Drupal\libraries\ExternalLibrary\LibraryManagerInterface $library_manager
51 * The library manager that can be used to fetch dependencies.
55 * @see \Drupal\libraries\ExternalLibrary\Asset\SingleAssetLibraryTrait
57 * @throws \Drupal\libraries\ExternalLibrary\Exception\InvalidLibraryDependencyException
59 * @todo Document the return value.
60 * @todo Reconsider passing the library manager.
62 public function getAttachableAssetLibraries(LibraryManagerInterface $library_manager);