remoteUrl = $definition['remote_url']; $this->libraries = $definition['libraries']; } /** * {@inheritdoc} */ protected static function processDefinition(array &$definition) { parent::processDefinition($definition); $definition += [ 'remote_url' => '', 'libraries' => [], ]; foreach ($definition['libraries'] as &$library) { $library += [ 'css' => [], 'js' => [], '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 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; } /** * 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://'])); } }