3 namespace Drupal\Core\Config;
5 use Symfony\Component\EventDispatcher\Event;
8 * Gets information on all the possible configuration collections.
10 class ConfigCollectionInfo extends Event {
13 * Configuration collection information keyed by collection name.
15 * The value is either the configuration factory override that is responsible
16 * for the collection or null if there is not one.
20 protected $collections = [];
23 * Adds a collection to the list of possible collections.
25 * @param string $collection
26 * Collection name to add.
27 * @param \Drupal\Core\Config\ConfigFactoryOverrideInterface $override_service
28 * (optional) The configuration factory override service responsible for the
31 * @throws \InvalidArgumentException
32 * Exception thrown if $collection is equal to
33 * \Drupal\Core\Config\StorageInterface::DEFAULT_COLLECTION.
35 public function addCollection($collection, ConfigFactoryOverrideInterface $override_service = NULL) {
36 if ($collection == StorageInterface::DEFAULT_COLLECTION) {
37 throw new \InvalidArgumentException('Can not add the default collection to the ConfigCollectionInfo object');
39 $this->collections[$collection] = $override_service;
43 * Gets the list of possible collection names.
45 * @param bool $include_default
46 * (Optional) Include the default collection. Defaults to TRUE.
49 * The list of possible collection names.
51 public function getCollectionNames($include_default = TRUE) {
52 $collection_names = array_keys($this->collections);
53 sort($collection_names);
54 if ($include_default) {
55 array_unshift($collection_names, StorageInterface::DEFAULT_COLLECTION);
57 return $collection_names;
61 * Gets the config factory override service responsible for the collection.
63 * @param string $collection
64 * The configuration collection.
66 * @return \Drupal\Core\Config\ConfigFactoryOverrideInterface|null
67 * The override service responsible for the collection if one exists. NULL
70 public function getOverrideService($collection) {
71 return isset($this->collections[$collection]) ? $this->collections[$collection] : NULL;