ConfigOverride.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace Drupal\Core\Installer;
  3. use Drupal\Core\Cache\CacheableMetadata;
  4. use Drupal\Core\Config\ConfigFactoryOverrideInterface;
  5. use Drupal\Core\Config\StorageInterface;
  6. use Drupal\Core\DependencyInjection\ContainerBuilder;
  7. use Drupal\Core\DependencyInjection\ServiceProviderInterface;
  8. /**
  9. * Override configuration during the installer.
  10. */
  11. class ConfigOverride implements ServiceProviderInterface, ConfigFactoryOverrideInterface {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function register(ContainerBuilder $container) {
  16. // Register this class so that it can override configuration.
  17. $container
  18. ->register('core.install_config_override', static::class)
  19. ->addTag('config.factory.override');
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function loadOverrides($names) {
  25. $overrides = [];
  26. if (drupal_installation_attempted() && function_exists('drupal_install_profile_distribution_name')) {
  27. // Early in the installer the site name is unknown. In this case we need
  28. // to fallback to the distribution's name.
  29. $overrides['system.site'] = [
  30. 'name' => drupal_install_profile_distribution_name(),
  31. ];
  32. }
  33. return $overrides;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function getCacheSuffix() {
  39. return 'core.install_config_override';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
  45. return NULL;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. public function getCacheableMetadata($name) {
  51. return new CacheableMetadata();
  52. }
  53. }