FeaturesInstallStorage.php
5.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
/**
* @file
* Contains \Drupal\features\FeaturesInstallStorage.
*/
namespace Drupal\features;
use Drupal\Core\Site\Settings;
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Extension\ExtensionDiscovery;
/**
* Storage to access configuration and schema in enabled extensions.
*
* Overrides the normal ExtensionInstallStorage to prevent profile from
* overriding.
*
* Also supports modules that are not installed yet.
*
* @see \Drupal\Core\Config\ExtensionInstallStorage
*/
class FeaturesInstallStorage extends ExtensionInstallStorage {
/**
* Overrides \Drupal\Core\Config\ExtensionInstallStorage::__construct().
*
* Sets includeProfile to FALSE.
*
* @param \Drupal\Core\Config\StorageInterface $config_storage
* The active configuration store where the list of enabled modules and
* themes is stored.
* @param string $directory
* The directory to scan in each extension to scan for files. Defaults to
* 'config/install'.
* @param string $collection
* (optional) The collection to store configuration in. Defaults to the
* default collection.
*/
public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY, $collection = StorageInterface::DEFAULT_COLLECTION) {
parent::__construct($config_storage, $directory, $collection, FALSE);
}
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* NOTE: This code is copied from ExtensionInstallStorage::getAllFolders() with
* the following changes (Notes in CHANGED below)
* - Load all modules whether installed or not
*
* @return array
* An array mapping config object names with directories.
*/
public function getAllFolders() {
if (!isset($this->folders)) {
$this->folders = array();
$this->folders += $this->getCoreNames();
$install_profile = Settings::get('install_profile');
$profile = drupal_get_profile();
$extensions = $this->configStorage->read('core.extension');
// @todo Remove this scan as part of https://www.drupal.org/node/2186491
$listing = new ExtensionDiscovery(\Drupal::root());
// CHANGED START: Add profile directories for any bundles that use a profile.
$profile_directories = [];
if ($profile) {
$profile_directories[] = drupal_get_path('profile', $profile);
}
if ($this->includeProfile) {
// Add any profiles used in bundles.
$assigner = \Drupal::service('features_assigner');
$bundles = $assigner->getBundleList();
foreach ($bundles as $bundle_name => $bundle) {
if ($bundle->isProfile()) {
// Register the profile directory.
$profile_directory = 'profiles/' . $bundle->getProfileName();
if (is_dir($profile_directory)) {
$profile_directories[] = $profile_directory;
}
}
}
}
$listing->setProfileDirectories($profile_directories);
// CHANGED END
if (!empty($extensions['module'])) {
// CHANGED START: Find ANY modules, not just enabled ones.
//$modules = $extensions['module'];
$module_list_scan = $listing->scan('module');
$modules = $module_list_scan;
// CHANGED END
// Remove the install profile as this is handled later.
unset($modules[$install_profile]);
$profile_list = $listing->scan('profile');
if ($profile && isset($profile_list[$profile])) {
// Prime the drupal_get_filename() static cache with the profile info
// file location so we can use drupal_get_path() on the active profile
// during the module scan.
// @todo Remove as part of https://www.drupal.org/node/2186491
drupal_get_filename('profile', $profile, $profile_list[$profile]->getPathname());
}
$module_list = array();
foreach (array_keys($module_list_scan) as $module) {
if (isset($module_list_scan[$module])) {
$module_list[$module] = $module_list_scan[$module];
}
}
$this->folders += $this->getComponentNames($module_list);
}
if (!empty($extensions['theme'])) {
$theme_list_scan = $listing->scan('theme');
foreach (array_keys($extensions['theme']) as $theme) {
if (isset($theme_list_scan[$theme])) {
$theme_list[$theme] = $theme_list_scan[$theme];
}
}
$this->folders += $this->getComponentNames($theme_list);
}
if ($this->includeProfile) {
// The install profile can override module default configuration. We do
// this by replacing the config file path from the module/theme with the
// install profile version if there are any duplicates.
if (isset($profile)) {
if (!isset($profile_list)) {
$profile_list = $listing->scan('profile');
}
if (isset($profile_list[$profile])) {
$profile_folders = $this->getComponentNames(array($profile_list[$profile]));
$this->folders = $profile_folders + $this->folders;
}
}
}
}
return $this->folders;
}
}