3 namespace Drupal\libraries\Plugin\libraries\Locator;
5 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
6 use Drupal\Core\Config\ConfigFactoryInterface;
7 use Drupal\Component\Plugin\Factory\FactoryInterface;
8 use Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface;
9 use Drupal\libraries\ExternalLibrary\Local\LocatorInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Provides a locator based on global configuration.
17 * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface
19 class GlobalLocator implements LocatorInterface, ContainerFactoryPluginInterface {
22 * The Drupal config factory service.
24 * @var \Drupal\Core\Config\ConfigFactoryInterface
26 protected $configFactory;
29 * The locator factory.
31 * @var \Drupal\Component\Plugin\Factory\FactoryInterface
33 protected $locatorFactory;
36 * Constructs a global locator.
38 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
39 * The Drupal config factory service.
40 * @param \Drupal\Component\Plugin\Factory\FactoryInterface $locator_factory
41 * The locator factory.
43 public function __construct(ConfigFactoryInterface $config_factory, FactoryInterface $locator_factory) {
44 $this->configFactory = $config_factory;
45 $this->locatorFactory = $locator_factory;
51 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
53 $container->get('config.factory'),
54 $container->get('plugin.manager.libraries.locator')
61 * @param \Drupal\libraries\ExternalLibrary\Local\LocalLibraryInterface $library
62 * The library to locate.
64 * @see \Drupal\libraries\ExternalLibrary\Local\LocatorInterface::locate()
66 public function locate(LocalLibraryInterface $library) {
67 foreach ($this->configFactory->get('libraries.settings')->get('global_locators') as $locator) {
68 $this->locatorFactory->createInstance($locator['id'], $locator['configuration'])->locate($library);
69 if ($library->isInstalled()) {
73 $library->setUninstalled();