You are here

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

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\Asset
View 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

Namesort descending Modifiers Type Description Overrides
AssetLibraryInterface::getAttachableAssetLibrary public function Returns a core asset library array structure for this library. 1
DependentLibraryInterface::getDependencies public function Returns the libraries dependencies, if any.
LibraryInterface::create public static function Creates an instance of the library from its definition. 1
LibraryInterface::getId public function Returns the ID of the library.
LibraryInterface::getType public function Returns the library type of the library. 1
VersionedLibraryInterface::getVersion public function Gets the version of the library.
VersionedLibraryInterface::getVersionDetector public function Gets the version detector of this library using the detector factory.
VersionedLibraryInterface::setVersion public function Sets the version of the library.