AssetLibrary.php in Libraries API 8.3
File
src/ExternalLibrary/Asset/AssetLibrary.php
View source
<?php
namespace Drupal\libraries\ExternalLibrary\Asset;
use Drupal\Component\Plugin\Factory\FactoryInterface;
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;
class AssetLibrary extends LibraryBase implements AssetLibraryInterface, LocalLibraryInterface, RemoteLibraryInterface {
use LocalLibraryTrait, RemoteLibraryTrait, LocalRemoteAssetTrait;
protected $cssAssets = [];
protected $jsAssets = [];
protected $attachableDependencies = [];
public function __construct($id, array $definition, LibraryTypeInterface $library_type) {
parent::__construct($id, $definition, $library_type);
$this->remoteUrl = $definition['remote_url'];
$this->cssAssets = $definition['css'];
$this->jsAssets = $definition['js'];
$this->attachableDependencies = $definition['attachable_dependencies'];
}
protected static function processDefinition(array &$definition) {
parent::processDefinition($definition);
$definition += [
'remote_url' => '',
'css' => [],
'js' => [],
'attachable_dependencies' => [],
];
}
public function getAttachableAssetLibrary(LibraryManagerInterface $library_manager) {
if (!$this
->canBeAttached()) {
throw new LibraryNotInstalledException($this);
}
return [
'version' => $this
->getVersion(),
'css' => $this
->processCssAssets($this->cssAssets),
'js' => $this
->processJsAssets($this->jsAssets),
'dependencies' => $this->attachableDependencies,
];
}
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://',
]));
}
}
Classes
Name |
Description |
AssetLibrary |
Provides a class for a single attachable asset library. |