ExtensionInstallStorage.php 5.2 KB

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