streamWrapperManager = $stream_wrapper_manager; $this->uri = (string) $uri; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { if (!isset($configuration['uri'])) { throw new MissingPluginConfigurationException($plugin_id, $plugin_definition, $configuration, 'uri'); } return new static($container->get('stream_wrapper_manager'), $configuration['uri']); } /** * Locates a library. * * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library * The library to locate. * * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate() */ public function locate(LocalLibraryInterface $library) { /** @var \Drupal\Core\StreamWrapper\LocalStream $stream_wrapper */ $stream_wrapper = $this->streamWrapperManager->getViaUri($this->uri); assert('$stream_wrapper instanceof \Drupal\Core\StreamWrapper\LocalStream'); // Calling LocalStream::getDirectoryPath() explicitly avoids the realpath() // usage in LocalStream::getLocalPath(), which breaks if Libraries API is // symbolically linked into the Drupal installation. list($scheme, $target) = explode('://', $this->uri, 2); $base_path = str_replace('//', '/', $stream_wrapper->getDirectoryPath() . '/' . $target . '/' . $library->getId()); if (is_dir($base_path) && is_readable($base_path)) { $library->setLocalPath($base_path); return; } $library->setUninstalled(); } }