You are here

class DomainConfigOverride in Domain Site Settings 8

Overrides the config with the saved domain specific settings.

@package Drupal\domain_site_settings

Hierarchy

Expanded class hierarchy of DomainConfigOverride

1 string reference to 'DomainConfigOverride'
domain_site_settings.services.yml in ./domain_site_settings.services.yml
domain_site_settings.services.yml
1 service uses DomainConfigOverride
domain_site_settings.overrider in ./domain_site_settings.services.yml
Drupal\domain_site_settings\Configuration\DomainConfigOverride

File

src/Configuration/DomainConfigOverride.php, line 15

Namespace

Drupal\domain_site_settings\Configuration
View source
class DomainConfigOverride implements ConfigFactoryOverrideInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a DomainSourcePathProcessor object.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The module handler service.
   */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritDoc}
   */
  public function loadOverrides($names = []) {
    $overrides = [];
    if (in_array('system.site', $names)) {

      /** @var \Drupal\domain\DomainNegotiator $negotiator */
      $negotiator = \Drupal::service('domain.negotiator');
      $domain = $negotiator
        ->getActiveDomain();
      if (!empty($domain)) {
        $domain_key = $domain
          ->id();
        $configFactory = $this->configFactory
          ->get('domain_site_settings.domainconfigsettings');
        if ($configFactory
          ->get($domain_key) !== NULL) {
          $site_name = $configFactory
            ->get($domain_key . '.site_name');
          $site_slogan = $configFactory
            ->get($domain_key . '.site_slogan');
          $site_mail = $configFactory
            ->get($domain_key . '.site_mail');
          $site_403 = $configFactory
            ->get($domain_key . '.site_403');
          $site_404 = $configFactory
            ->get($domain_key . '.site_404');
          $site_front = $configFactory
            ->get($domain_key . '.site_frontpage');
          $front = $site_front !== \NULL ? $site_front : '/node';

          // Create the new settings array to override the configuration.
          $overrides['system.site'] = [
            'name' => $site_name,
            'slogan' => $site_slogan,
            'mail' => $site_mail,
            'page' => [
              '403' => $site_403,
              '404' => $site_404,
              'front' => $front,
            ],
          ];
        }
      }
    }
    return $overrides;
  }

  /**
   * {@inheritDoc}
   */
  public function getCacheSuffix() {
    return 'MultiSiteConfigurationOverrider';
  }

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

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

}

Members

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