Skip to content
Snippets Groups Projects
Commit 1b902538 authored by Guillaume Pacilly's avatar Guillaume Pacilly
Browse files

Merge branch '3388388-domainlanguageoverrider-service-arguments' into '2.0.x'

apply patch modifications

See merge request !15
parents 00be4ef7 211095a1
No related branches found
No related tags found
No related merge requests found
Pipeline #354208 passed with warnings
...@@ -3,4 +3,4 @@ services: ...@@ -3,4 +3,4 @@ services:
class: Drupal\domain_language\DomainLanguageOverrider class: Drupal\domain_language\DomainLanguageOverrider
tags: tags:
- { name: config.factory.override, priority: -140 } - { name: config.factory.override, priority: -140 }
arguments: ['@config.storage'] arguments: ['@current_user', '@config.factory', '@domain_config.overrider']
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
namespace Drupal\domain_language; namespace Drupal\domain_language;
use Drupal\domain\DomainNegotiatorInterface;
use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ConfigFactoryOverrideInterface;
use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Session\AccountProxyInterface;
use Drupal\domain_config\OverriderInterface; use Drupal\domain_config\DomainConfigOverrider;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
...@@ -18,40 +17,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface; ...@@ -18,40 +17,19 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class DomainLanguageOverrider implements ConfigFactoryOverrideInterface { class DomainLanguageOverrider implements ConfigFactoryOverrideInterface {
/** /**
* The current user. * The domain context of the request.
* *
* @var \Drupal\Core\Session\AccountProxyInterface * @var \Drupal\domain\DomainInterface
*/ */
protected $currentUser; protected $domain;
/** /**
* The domain negotiator. * The domain negotiator.
* *
* @var \Drupal\domain\DomainNegotiatorInterface * @var \Drupal\domain\DomainNegotiatorInterface|null
*/ */
protected $domainNegotiator; protected $domainNegotiator;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The domain config overrider service.
*
* @var \Drupal\domain_config\OverriderInterface
*/
protected $overrider;
/**
* The domain context of the request.
*
* @var \Drupal\domain\DomainInterface
*/
protected $domain;
/** /**
* Nested Level. * Nested Level.
* *
...@@ -69,35 +47,21 @@ class DomainLanguageOverrider implements ConfigFactoryOverrideInterface { ...@@ -69,35 +47,21 @@ class DomainLanguageOverrider implements ConfigFactoryOverrideInterface {
/** /**
* Constructs a DomainLanguageOverrider object. * Constructs a DomainLanguageOverrider object.
* *
* @param \Drupal\Core\Session\AccountProxyInterface $current_user * @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user. * The current user.
* @param \Drupal\domain\DomainNegotiatorInterface $domain_negotiator * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The domain negotiator.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory. * The configuration factory.
* @param \Drupal\domain_config\OverriderInterface $overrider * @param \Drupal\domain_config\DomainConfigOverrider $overrider
* The domain config overrider service. * The domain config overrider service.
*/ */
public function __construct(AccountProxyInterface $current_user, DomainNegotiatorInterface $domain_negotiator, ConfigFactoryInterface $config_factory, OverriderInterface $overrider) { public function __construct(
$this->currentUser = $current_user; protected AccountProxyInterface $currentUser,
$this->domainNegotiator = $domain_negotiator; protected ConfigFactoryInterface $configFactory,
$this->configFactory = $config_factory; protected DomainConfigOverrider $overrider,
$this->overrider = $overrider; ) {
$this->nestedLevel = 0; $this->nestedLevel = 0;
} }
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user'),
$container->get('domain.negotiator'),
$container->get('config.factory'),
$container->get('domain_config.overrider')
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -196,11 +160,24 @@ class DomainLanguageOverrider implements ConfigFactoryOverrideInterface { ...@@ -196,11 +160,24 @@ class DomainLanguageOverrider implements ConfigFactoryOverrideInterface {
*/ */
protected function initiateContext() { protected function initiateContext() {
$this->contextSet = TRUE; $this->contextSet = TRUE;
$this->domain = $this->domainNegotiator->getActiveDomain(); $this->domain = $this->getDomainNegotiator()->getActiveDomain();
// If we have fired too early in the bootstrap, we must force the routine to run. // If we have fired too early in the bootstrap, we must force the routine to run.
if (empty($this->domain)) { if (empty($this->domain)) {
$this->domain = $this->domainNegotiator->getActiveDomain(TRUE); $this->domain = $this->getDomainNegotiator()->getActiveDomain(TRUE);
}
}
/**
* Gets the domain negotiator service.
*
* @return \Drupal\domain\DomainNegotiatorInterface
* The domain negotiator service.
*/
protected function getDomainNegotiator() {
if (!isset($this->domainNegotiator)) {
$this->domainNegotiator = \Drupal::service('domain.negotiator');
} }
return $this->domainNegotiator;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment