You are here

public function DomainConfigOverride::loadOverrides in Domain Site Settings 8

Returns config overrides.

Parameters

array $names: A list of configuration names that are being loaded.

Return value

array An array keyed by configuration name of override data. Override data contains a nested array structure of overrides.

Overrides ConfigFactoryOverrideInterface::loadOverrides

File

src/Configuration/DomainConfigOverride.php, line 37

Class

DomainConfigOverride
Overrides the config with the saved domain specific settings.

Namespace

Drupal\domain_site_settings\Configuration

Code

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;
}