Further modules included.
[yaffs-website] / web / modules / contrib / libraries / src / Plugin / libraries / Type / MultipleAssetLibraryType.php
1 <?php
2
3 namespace Drupal\libraries\Plugin\libraries\Type;
4
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;
11
12 /**
13  * @LibraryType("asset_multiple")
14  */
15 class MultipleAssetLibraryType extends LibraryTypeBase implements AttachableAssetLibraryRegistrationInterface {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function getLibraryClass() {
21     return MultipleAssetLibrary::class;
22   }
23
24   /**
25    * {@inheritdoc}
26    */
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;
34     }
35     return $attachable_libraries;
36   }
37
38   /**
39    * @param \Drupal\libraries\ExternalLibrary\LibraryInterface $external_library
40    * @param string $component_name
41    *
42    * @return string
43    */
44   protected function getAttachableLibraryId(LibraryInterface $external_library, $component_name) {
45     return $external_library->getId() . MultipleAssetLibraryInterface::SEPARATOR . $component_name;
46   }
47
48 }