You are here

class SiteConfigOverrides in Config override 8

Hierarchy

Expanded class hierarchy of SiteConfigOverrides

1 file declares its use of SiteConfigOverrides
SiteConfigOverridesTest.php in tests/Unit/SiteConfigOverridesTest.php
1 string reference to 'SiteConfigOverrides'
config_override.services.yml in ./config_override.services.yml
config_override.services.yml
1 service uses SiteConfigOverrides
config_override.override_site in ./config_override.services.yml
\Drupal\config_override\SiteConfigOverrides

File

src/SiteConfigOverrides.php, line 12

Namespace

Drupal\config_override
View source
class SiteConfigOverrides implements ConfigFactoryOverrideInterface {

  /**
   * Constants for the override directory.
   */
  const CONFIG_OVERRIDE_DIRECTORY = 'override';

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

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

  /**
   * Creates a new SiteConfigOverrides instance.
   *
   * @param string $root
   *   The app root.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
   *   The cache backend.
   */
  public function __construct($root, CacheBackendInterface $cacheBackend) {
    $this->root = $root;
    $this->cacheBackend = $cacheBackend;
  }

  /**
   * {@inheritdoc}
   */
  public function loadOverrides($names) {
    $overrides = [];
    if (!($directory = $this
      ->getSiteConfigOverrideFolder())) {
      return $overrides;
    }
    if ($config = $this->cacheBackend
      ->get('config_overrides.site')) {
      $overrides = $config->data;
    }
    else {
      $storage = new FileStorage($this
        ->getSiteConfigOverrideFolder());
      $overrides = $storage
        ->readMultiple($storage
        ->listAll());
      $this->cacheBackend
        ->set('config_overrides.site', $overrides);
    }
    return array_intersect_key($overrides, array_flip($names));
  }

  /**
   * Returns the site config overrides directory or NULL if it was not defined.
   *
   * @return string|null
   *   The site config overrides directory or NULL if it was not defined.
   */
  protected function getSiteConfigOverrideFolder() {
    try {
      return $this->root . '/' . Settings::get('config_sync_directory');
    } catch (\Exception $e) {
      return NULL;
    }
  }

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

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

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata($name) {
    return new CacheableMetadata();
  }

  /**
   * {@inheritdoc}
   */
  protected function configGetConfigDirectory($override) {
    return 'sites/default/config/' . $override;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SiteConfigOverrides::$cacheBackend protected property
SiteConfigOverrides::$root protected property The app root.
SiteConfigOverrides::configGetConfigDirectory protected function
SiteConfigOverrides::CONFIG_OVERRIDE_DIRECTORY constant Constants for the override directory.
SiteConfigOverrides::createConfigObject public function Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface::createConfigObject
SiteConfigOverrides::getCacheableMetadata public function Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface::getCacheableMetadata
SiteConfigOverrides::getCacheSuffix public function The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface::getCacheSuffix
SiteConfigOverrides::getSiteConfigOverrideFolder protected function Returns the site config overrides directory or NULL if it was not defined.
SiteConfigOverrides::loadOverrides public function Returns config overrides. Overrides ConfigFactoryOverrideInterface::loadOverrides
SiteConfigOverrides::__construct public function Creates a new SiteConfigOverrides instance.