3 namespace Drupal\libraries\Plugin\libraries\Type;
5 use Drupal\libraries\ExternalLibrary\Asset\AttachableAssetLibraryRegistrationInterface;
6 use Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibrary;
7 use Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface;
8 use Drupal\libraries\ExternalLibrary\LibraryInterface;
9 use Drupal\libraries\ExternalLibrary\LibraryManagerInterface;
10 use Drupal\libraries\ExternalLibrary\Type\LibraryTypeBase;
13 * @LibraryType("asset_multiple")
15 class MultipleAssetLibraryType extends LibraryTypeBase implements AttachableAssetLibraryRegistrationInterface {
20 public function getLibraryClass() {
21 return MultipleAssetLibrary::class;
27 public function getAttachableAssetLibraries(LibraryInterface $external_library, LibraryManagerInterface $library_manager) {
28 assert('$external_library instanceof \Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface');
29 /** @var \Drupal\libraries\ExternalLibrary\Asset\MultipleAssetLibraryInterface $external_library */
30 $attachable_libraries = [];
31 foreach ($external_library->getAttachableAssetLibraries($library_manager) as $component_name => $attachable_library) {
32 $attachable_library_id = $this->getAttachableLibraryId($external_library, $component_name);
33 $attachable_libraries[$attachable_library_id] = $attachable_library;
35 return $attachable_libraries;
39 * @param \Drupal\libraries\ExternalLibrary\LibraryInterface $external_library
40 * @param string $component_name
44 protected function getAttachableLibraryId(LibraryInterface $external_library, $component_name) {
45 return $external_library->getId() . MultipleAssetLibraryInterface::SEPARATOR . $component_name;