X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FExternalLibrary%2FAsset%2FAssetLibrary.php;fp=web%2Fmodules%2Fcontrib%2Flibraries%2Fsrc%2FExternalLibrary%2FAsset%2FAssetLibrary.php;h=50a31868682d824ee0f3cdcc7fa35d0b3f963a8d;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/libraries/src/ExternalLibrary/Asset/AssetLibrary.php b/web/modules/contrib/libraries/src/ExternalLibrary/Asset/AssetLibrary.php new file mode 100644 index 000000000..50a318686 --- /dev/null +++ b/web/modules/contrib/libraries/src/ExternalLibrary/Asset/AssetLibrary.php @@ -0,0 +1,128 @@ +remoteUrl = $definition['remote_url']; + $this->cssAssets = $definition['css']; + $this->jsAssets = $definition['js']; + $this->attachableDependencies = $definition['attachable_dependencies']; + } + + /** + * {@inheritdoc} + */ + protected static function processDefinition(array &$definition) { + parent::processDefinition($definition); + $definition += [ + 'remote_url' => '', + 'css' => [], + 'js' => [], + 'attachable_dependencies' => [], + ]; + } + + /** + * Returns a core 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\getAttachableAssetLibraries::getAttachableAssetLibraries() + * + * @throws \Drupal\libraries\ExternalLibrary\Exception\InvalidLibraryDependencyException + * @throws \Drupal\libraries\ExternalLibrary\Exception\LibraryDefinitionNotFoundException + * @throws \Drupal\libraries\ExternalLibrary\Exception\LibraryTypeNotFoundException + * @throws \Drupal\Component\Plugin\Exception\PluginException + * + * @todo Document the return value. + */ + 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, + ]; + } + + /** + * Gets the locator of this library using the locator factory. + * + * @param \Drupal\Component\Plugin\Factory\FactoryInterface $locator_factory + * + * @return \Drupal\libraries\ExternalLibrary\Local\LocatorInterface + * + * @see \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface::getLocator() + */ + public function getLocator(FactoryInterface $locator_factory) { + // @todo Consider consolidating the stream wrappers used here. For now we + // allow asset libs to live almost anywhere. + return $locator_factory->createInstance('chain') + ->addLocator($locator_factory->createInstance('uri', ['uri' => 'asset://'])) + ->addLocator($locator_factory->createInstance('uri', ['uri' => 'php-file://'])); + } + +}