Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / lib / Drupal / Core / Config / ExtensionInstallStorage.php
1 <?php
2
3 namespace Drupal\Core\Config;
4
5 use Drupal\Core\Extension\ExtensionDiscovery;
6
7 /**
8  * Storage to access configuration and schema in enabled extensions.
9  *
10  * @see \Drupal\Core\Config\ConfigInstaller
11  * @see \Drupal\Core\Config\TypedConfigManager
12  */
13 class ExtensionInstallStorage extends InstallStorage {
14
15   /**
16    * The active configuration store.
17    *
18    * @var \Drupal\Core\Config\StorageInterface
19    */
20   protected $configStorage;
21
22   /**
23    * Flag to include the profile in the list of enabled modules.
24    *
25    * @var bool
26    */
27   protected $includeProfile = TRUE;
28
29   /**
30    * The name of the currently active installation profile.
31    *
32    * @var string
33    */
34   protected $installProfile;
35
36   /**
37    * Overrides \Drupal\Core\Config\InstallStorage::__construct().
38    *
39    * @param \Drupal\Core\Config\StorageInterface $config_storage
40    *   The active configuration store where the list of enabled modules and
41    *   themes is stored.
42    * @param string $directory
43    *   The directory to scan in each extension to scan for files. Defaults to
44    *   'config/install'.
45    * @param string $collection
46    *   (optional) The collection to store configuration in. Defaults to the
47    *   default collection.
48    * @param bool $include_profile
49    *   (optional) Whether to include the install profile in extensions to
50    *   search and to get overrides from.
51    * @param string $profile
52    *   (optional) The current installation profile. This parameter will be
53    *   mandatory in Drupal 9.0.0. In Drupal 8.3.0 not providing this parameter
54    *   will trigger a silenced deprecation warning.
55    */
56   public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION, $include_profile = TRUE, $profile = NULL) {
57     parent::__construct($directory, $collection);
58     $this->configStorage = $config_storage;
59     $this->includeProfile = $include_profile;
60     if (is_null($profile)) {
61       @trigger_error('Install profile will be a mandatory parameter in Drupal 9.0.', E_USER_DEPRECATED);
62     }
63     $this->installProfile = $profile ?: \Drupal::installProfile();
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function createCollection($collection) {
70     return new static(
71       $this->configStorage,
72       $this->directory,
73       $collection
74     );
75   }
76
77   /**
78    * Returns a map of all config object names and their folders.
79    *
80    * The list is based on enabled modules and themes. The active configuration
81    * storage is used rather than \Drupal\Core\Extension\ModuleHandler and
82    *  \Drupal\Core\Extension\ThemeHandler in order to resolve circular
83    * dependencies between these services and \Drupal\Core\Config\ConfigInstaller
84    * and \Drupal\Core\Config\TypedConfigManager.
85    *
86    * @return array
87    *   An array mapping config object names with directories.
88    */
89   protected function getAllFolders() {
90     if (!isset($this->folders)) {
91       $this->folders = [];
92       $this->folders += $this->getCoreNames();
93
94       $extensions = $this->configStorage->read('core.extension');
95       // @todo Remove this scan as part of https://www.drupal.org/node/2186491
96       $listing = new ExtensionDiscovery(\Drupal::root());
97       if (!empty($extensions['module'])) {
98         $modules = $extensions['module'];
99         // Remove the install profile as this is handled later.
100         unset($modules[$this->installProfile]);
101         $profile_list = $listing->scan('profile');
102         if ($this->installProfile && isset($profile_list[$this->installProfile])) {
103           // Prime the drupal_get_filename() static cache with the profile info
104           // file location so we can use drupal_get_path() on the active profile
105           // during the module scan.
106           // @todo Remove as part of https://www.drupal.org/node/2186491
107           drupal_get_filename('profile', $this->installProfile, $profile_list[$this->installProfile]->getPathname());
108         }
109         $module_list_scan = $listing->scan('module');
110         $module_list = [];
111         foreach (array_keys($modules) as $module) {
112           if (isset($module_list_scan[$module])) {
113             $module_list[$module] = $module_list_scan[$module];
114           }
115         }
116         $this->folders += $this->getComponentNames($module_list);
117       }
118       if (!empty($extensions['theme'])) {
119         $theme_list_scan = $listing->scan('theme');
120         foreach (array_keys($extensions['theme']) as $theme) {
121           if (isset($theme_list_scan[$theme])) {
122             $theme_list[$theme] = $theme_list_scan[$theme];
123           }
124         }
125         $this->folders += $this->getComponentNames($theme_list);
126       }
127
128       if ($this->includeProfile) {
129         // The install profile can override module default configuration. We do
130         // this by replacing the config file path from the module/theme with the
131         // install profile version if there are any duplicates.
132         if ($this->installProfile) {
133           if (!isset($profile_list)) {
134             $profile_list = $listing->scan('profile');
135           }
136           if (isset($profile_list[$this->installProfile])) {
137             $profile_folders = $this->getComponentNames([$profile_list[$this->installProfile]]);
138             $this->folders = $profile_folders + $this->folders;
139           }
140         }
141       }
142     }
143     return $this->folders;
144   }
145
146 }