MultipleAssetLibrary.php in Libraries API 8.3
File
src/ExternalLibrary/Asset/MultipleAssetLibrary.php
View source
<?php
namespace Drupal\libraries\ExternalLibrary\Asset;
use Drupal\Component\Plugin\Factory\FactoryInterface;
use Drupal\libraries\ExternalLibrary\Dependency\DependentLibraryInterface;
use Drupal\libraries\ExternalLibrary\Exception\LibraryNotInstalledException;
use Drupal\libraries\ExternalLibrary\LibraryBase;
use Drupal\libraries\ExternalLibrary\LibraryManagerInterface;
use Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface;
use Drupal\libraries\ExternalLibrary\Local\LocalLibraryTrait;
use Drupal\libraries\ExternalLibrary\Remote\RemoteLibraryInterface;
use Drupal\libraries\ExternalLibrary\Remote\RemoteLibraryTrait;
use Drupal\libraries\ExternalLibrary\Type\LibraryTypeInterface;
use Drupal\libraries\ExternalLibrary\Version\VersionedLibraryInterface;
class MultipleAssetLibrary extends LibraryBase implements MultipleAssetLibraryInterface, VersionedLibraryInterface, DependentLibraryInterface, LocalLibraryInterface, RemoteLibraryInterface {
use LocalLibraryTrait, RemoteLibraryTrait, LocalRemoteAssetTrait;
protected $libraries = [];
public function __construct($id, array $definition, LibraryTypeInterface $library_type) {
parent::__construct($id, $definition, $library_type);
$this->remoteUrl = $definition['remote_url'];
$this->libraries = $definition['libraries'];
}
protected static function processDefinition(array &$definition) {
parent::processDefinition($definition);
$definition += [
'remote_url' => '',
'libraries' => [],
];
foreach ($definition['libraries'] as &$library) {
$library += [
'css' => [],
'js' => [],
'dependencies' => [],
];
}
}
public function getAttachableAssetLibraries(LibraryManagerInterface $library_manager) {
if (!$this
->canBeAttached()) {
throw new LibraryNotInstalledException($this);
}
$attachable_libraries = [];
foreach ($this->libraries as $attachable_library_id => $attachable_library) {
$attachable_libraries[$attachable_library_id] = [
'version' => $this
->getVersion(),
'css' => $this
->processCssAssets($attachable_library['css']),
'js' => $this
->processJsAssets($attachable_library['js']),
'dependencies' => $attachable_library['dependencies'],
];
}
return $attachable_libraries;
}
public function getLocator(FactoryInterface $locator_factory) {
return $locator_factory
->createInstance('chain')
->addLocator($locator_factory
->createInstance('uri', [
'uri' => 'asset://',
]))
->addLocator($locator_factory
->createInstance('uri', [
'uri' => 'php-file://',
]));
}
}