6578f42c6d6eaae190575fb48d42832ad92f28bf
[yaffs-website] / web / modules / contrib / libraries / src / Config / LibrariesConfigSubscriber.php
1 <?php
2
3 namespace Drupal\libraries\Config;
4
5 use Drupal\Core\Config\ConfigCrudEvent;
6 use Drupal\Core\Config\ConfigEvents;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10 /**
11  * Reacts to configuration changes of the 'libraries.settings' configuration.
12  */
13 class LibrariesConfigSubscriber implements EventSubscriberInterface {
14
15   /**
16    * The service container.
17    *
18    * @var \Symfony\Component\DependencyInjection\ContainerInterface
19    */
20   protected $container;
21
22   /**
23    * Constructs a Libraries API configuration subscriber.
24    *
25    * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
26    *   The service container.
27    */
28   public function __construct(ContainerInterface $container) {
29     $this->container = $container;
30   }
31
32   /**
33    * Unsets the definition discovery service when its configuration changes.
34    *
35    * @param \Drupal\Core\Config\ConfigCrudEvent $event
36    *   The configuration event.
37    */
38   public function onConfigSave(ConfigCrudEvent $event) {
39     if (($event->getConfig()->getName() === 'libraries.settings') && $event->isChanged('definition')) {
40       $this->container->set('libraries.definition.discovery', NULL);
41     }
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public static function getSubscribedEvents() {
48     return [ConfigEvents::SAVE => 'onConfigSave'];
49   }
50
51 }