Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Config / ConfigCollectionInfo.php
1 <?php
2
3 namespace Drupal\Core\Config;
4
5 use Symfony\Component\EventDispatcher\Event;
6
7 /**
8  * Gets information on all the possible configuration collections.
9  */
10 class ConfigCollectionInfo extends Event {
11
12   /**
13    * Configuration collection information keyed by collection name.
14    *
15    * The value is either the configuration factory override that is responsible
16    * for the collection or null if there is not one.
17    *
18    * @var array
19    */
20   protected $collections = [];
21
22   /**
23    * Adds a collection to the list of possible collections.
24    *
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
29    *   collection.
30    *
31    * @throws \InvalidArgumentException
32    *   Exception thrown if $collection is equal to
33    *   \Drupal\Core\Config\StorageInterface::DEFAULT_COLLECTION.
34    */
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');
38     }
39     $this->collections[$collection] = $override_service;
40   }
41
42   /**
43    * Gets the list of possible collection names.
44    *
45    * @param bool $include_default
46    *   (Optional) Include the default collection. Defaults to TRUE.
47    *
48    * @return array
49    *   The list of possible collection names.
50    */
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);
56     }
57     return $collection_names;
58   }
59
60   /**
61    * Gets the config factory override service responsible for the collection.
62    *
63    * @param string $collection
64    *   The configuration collection.
65    *
66    * @return \Drupal\Core\Config\ConfigFactoryOverrideInterface|null
67    *   The override service responsible for the collection if one exists. NULL
68    *   if not.
69    */
70   public function getOverrideService($collection) {
71     return isset($this->collections[$collection]) ? $this->collections[$collection] : NULL;
72   }
73
74 }