3 namespace Drupal\config_collection_install_test;
5 use Drupal\Core\Config\ConfigCollectionInfo;
6 use Drupal\Core\Config\ConfigEvents;
7 use Drupal\Core\State\StateInterface;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10 class EventSubscriber implements EventSubscriberInterface {
13 * The state key value store.
15 * @var \Drupal\Core\State\StateInterface
20 * Constructs the Event Subscriber object.
22 * @param \Drupal\Core\State\StateInterface $state
23 * The state key value store.
25 public function __construct(StateInterface $state) {
26 $this->state = $state;
30 * Reacts to the ConfigEvents::COLLECTION_INFO event.
32 * @param \Drupal\Core\Config\ConfigCollectionInfo $collection_info
33 * The configuration collection info event.
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);
45 public static function getSubscribedEvents() {
46 $events[ConfigEvents::COLLECTION_INFO][] = ['addCollections'];