Version 1
[yaffs-website] / web / core / modules / config / tests / config_collection_install_test / src / EventSubscriber.php
1 <?php
2
3 namespace Drupal\config_collection_install_test;
4
5 use Drupal\Core\Config\ConfigCollectionInfo;
6 use Drupal\Core\Config\ConfigEvents;
7 use Drupal\Core\State\StateInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
10 class EventSubscriber implements EventSubscriberInterface {
11
12   /**
13    * The state key value store.
14    *
15    * @var \Drupal\Core\State\StateInterface
16    */
17   protected $state;
18
19   /**
20    * Constructs the Event Subscriber object.
21    *
22    * @param \Drupal\Core\State\StateInterface $state
23    *   The state key value store.
24    */
25   public function __construct(StateInterface $state) {
26     $this->state = $state;
27   }
28
29   /**
30    * Reacts to the ConfigEvents::COLLECTION_INFO event.
31    *
32    * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info
33    *   The configuration collection info event.
34    */
35   public function addCollections(ConfigCollectionInfo $collection_info) {
36     $collections = $this->state->get('config_collection_install_test.collection_names', []);
37     foreach ($collections as $collection) {
38       $collection_info->addCollection($collection);
39     }
40   }
41
42   /**
43    * {@inheritdoc}
44    */
45   public static function getSubscribedEvents() {
46     $events[ConfigEvents::COLLECTION_INFO][] = ['addCollections'];
47     return $events;
48   }
49
50 }