You are here

class ModuleConfigOverrides in Config override 8

Hierarchy

Expanded class hierarchy of ModuleConfigOverrides

1 file declares its use of ModuleConfigOverrides
ModuleConfigOverridesTest.php in tests/Unit/ModuleConfigOverridesTest.php
1 string reference to 'ModuleConfigOverrides'
config_override.services.yml in ./config_override.services.yml
config_override.services.yml
1 service uses ModuleConfigOverrides
config_override.override_modules in ./config_override.services.yml
\Drupal\config_override\ModuleConfigOverrides

File

src/ModuleConfigOverrides.php, line 18
Contains \Drupal\config_override\ModuleConfigOverrides.

Namespace

Drupal\config_override
View source
class ModuleConfigOverrides implements ConfigFactoryOverrideInterface {

  /**
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cacheBackend;

  /**
   * The app root.
   *
   * @var string
   */
  protected $root;

  /**
   * Creates a new ModuleConfigOverrides instance.
   *
   * @param string $root
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
   */
  public function __construct($root, ModuleHandlerInterface $moduleHandler, CacheBackendInterface $cacheBackend) {
    $this->root = $root;
    $this->moduleHandler = $moduleHandler;
    $this->cacheBackend = $cacheBackend;
  }

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];
    if ($config = $this->cacheBackend
      ->get('config_overrides.modules')) {
      $overrides = $config->data;
    }
    else {
      $modules = $this->moduleHandler
        ->getModuleList();
      foreach ($modules as $module) {
        $folder = $this->root . '/' . $module
          ->getPath() . '/config/override';
        if (file_exists($folder)) {
          $file_storage = new FileStorage($folder);
          $overrides = NestedArray::mergeDeep($overrides, $file_storage
            ->readMultiple($file_storage
            ->listAll()));
        }
      }
      $this->cacheBackend
        ->set('config_overrides.modules', $overrides);
    }
    return array_intersect_key($overrides, array_flip($names));
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheSuffix() {
    return 'config_override.modules';
  }

  /**
   * {@inheritdoc}
   */
  public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    $cache_metadata = new CacheableMetadata();
    $cache_metadata
      ->addCacheTags([
      'extensions',
    ]);
    return $cache_metadata;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ModuleConfigOverrides::$cacheBackend protected property
ModuleConfigOverrides::$moduleHandler protected property
ModuleConfigOverrides::$root protected property The app root.
ModuleConfigOverrides::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
ModuleConfigOverrides::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
ModuleConfigOverrides::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
ModuleConfigOverrides::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides
ModuleConfigOverrides::__construct public function Creates a new ModuleConfigOverrides instance.