3 namespace Drupal\Core\Config;
5 use Drupal\Core\Extension\ExtensionDiscovery;
8 * Storage to access configuration and schema in enabled extensions.
10 * @see \Drupal\Core\Config\ConfigInstaller
11 * @see \Drupal\Core\Config\TypedConfigManager
13 class ExtensionInstallStorage extends InstallStorage {
16 * The active configuration store.
18 * @var \Drupal\Core\Config\StorageInterface
20 protected $configStorage;
23 * Flag to include the profile in the list of enabled modules.
27 protected $includeProfile = TRUE;
30 * The name of the currently active installation profile.
34 protected $installProfile;
37 * Overrides \Drupal\Core\Config\InstallStorage::__construct().
39 * @param \Drupal\Core\Config\StorageInterface $config_storage
40 * The active configuration store where the list of enabled modules and
42 * @param string $directory
43 * The directory to scan in each extension to scan for files. Defaults to
45 * @param string $collection
46 * (optional) The collection to store configuration in. Defaults to the
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.
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);
63 $this->installProfile = $profile ?: \Drupal::installProfile();
69 public function createCollection($collection) {
78 * Returns a map of all config object names and their folders.
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.
87 * An array mapping config object names with directories.
89 protected function getAllFolders() {
90 if (!isset($this->folders)) {
92 $this->folders += $this->getCoreNames();
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());
109 $module_list_scan = $listing->scan('module');
111 foreach (array_keys($modules) as $module) {
112 if (isset($module_list_scan[$module])) {
113 $module_list[$module] = $module_list_scan[$module];
116 $this->folders += $this->getComponentNames($module_list);
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];
125 $this->folders += $this->getComponentNames($theme_list);
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');
136 if (isset($profile_list[$this->installProfile])) {
137 $profile_folders = $this->getComponentNames([$profile_list[$this->installProfile]]);
138 $this->folders = $profile_folders + $this->folders;
143 return $this->folders;