ExtensionInstallStorage.php 5.5 KB

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