Commit 2b9631ac authored by alexpott's avatar alexpott

Issue #2300829 by Jose Reyero: Fixed Clean up LocaleConfigManager /...

Issue #2300829 by Jose Reyero: Fixed Clean up LocaleConfigManager / TypedConfigManager features and cache duplications.
parent 5106b55d
......@@ -8,6 +8,7 @@
namespace Drupal\config_translation;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Routing\RouteProviderInterface;
......@@ -61,6 +62,8 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* - entity_type: The name of the entity type this mapper belongs to.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\locale\LocaleConfigManager $locale_config_manager
* The locale configuration manager.
* @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
......@@ -72,8 +75,8 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager, EntityManagerInterface $entity_manager) {
parent::__construct($plugin_id, $plugin_definition, $config_factory, $locale_config_manager, $config_mapper_manager, $route_provider, $translation_manager);
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $translation_manager, EntityManagerInterface $entity_manager) {
parent::__construct($plugin_id, $plugin_definition, $config_factory, $typed_config, $locale_config_manager, $config_mapper_manager, $route_provider, $translation_manager);
$this->setType($plugin_definition['entity_type']);
$this->entityManager = $entity_manager;
......@@ -89,6 +92,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('config.factory'),
$container->get('config.typed'),
$container->get('locale.config.typed'),
$container->get('plugin.manager.config_translation.mapper'),
$container->get('router.route_provider'),
......
......@@ -8,6 +8,7 @@
namespace Drupal\config_translation;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Plugin\PluginBase;
......@@ -32,6 +33,13 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
*/
protected $configFactory;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
/**
* The typed configuration manager.
*
......@@ -91,6 +99,8 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* generate lists of this type of configuration.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\locale\LocaleConfigManager $locale_config_manager
* The locale configuration manager.
* @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
......@@ -104,12 +114,13 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
* Throws an exception if the route specified by the 'base_route_name' in
* the plugin definition could not be found by the route provider.
*/
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation) {
public function __construct($plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, LocaleConfigManager $locale_config_manager, ConfigMapperManagerInterface $config_mapper_manager, RouteProviderInterface $route_provider, TranslationInterface $string_translation) {
$this->pluginId = $plugin_id;
$this->pluginDefinition = $plugin_definition;
$this->routeProvider = $route_provider;
$this->configFactory = $config_factory;
$this->typedConfigManager = $typed_config;
$this->localeConfigManager = $locale_config_manager;
$this->configMapperManager = $config_mapper_manager;
......@@ -126,6 +137,7 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_id,
$plugin_definition,
$container->get('config.factory'),
$container->get('config.typed'),
$container->get('locale.config.typed'),
$container->get('plugin.manager.config_translation.mapper'),
$container->get('router.route_provider'),
......@@ -435,7 +447,7 @@ public function getConfigData() {
*/
public function hasSchema() {
foreach ($this->getConfigNames() as $name) {
if (!$this->localeConfigManager->hasConfigSchema($name)) {
if (!$this->typedConfigManager->hasConfigSchema($name)) {
return FALSE;
}
}
......
......@@ -67,6 +67,9 @@ public function setUp() {
'entity_type' => 'language_entity',
'route_name' => 'config_translation.item.overview.language.edit',
);
$typed_config_manager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
$locale_config_manager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
->disableOriginalConstructor()
->getMock();
......@@ -75,6 +78,7 @@ public function setUp() {
'language_entity',
$definition,
$this->getConfigFactoryStub(),
$typed_config_manager,
$locale_config_manager,
$this->getMock('Drupal\config_translation\ConfigMapperManagerInterface'),
$this->routeProvider,
......
......@@ -44,6 +44,13 @@ class ConfigNamesMapperTest extends UnitTestCase {
*/
protected $localeConfigManager;
/**
* The locale configuration manager.
*
* @var \Drupal\locale\LocaleConfigManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $typedConfigManager;
/**
* The configuration mapper manager.
*
......@@ -76,6 +83,8 @@ public function setUp() {
'weight' => 42,
);
$this->typedConfigManager = $this->getMock('Drupal\Core\Config\TypedConfigManagerInterface');
$this->localeConfigManager = $this->getMockBuilder('Drupal\locale\LocaleConfigManager')
->disableOriginalConstructor()
->getMock();
......@@ -94,6 +103,7 @@ public function setUp() {
'system.site_information_settings',
$this->pluginDefinition,
$this->getConfigFactoryStub(),
$this->typedConfigManager,
$this->localeConfigManager,
$this->configMapperManager,
$this->routeProvider,
......@@ -456,7 +466,7 @@ public function testHasSchema(array $mock_return_values, $expected) {
foreach ($config_names as $i => $config_name) {
$map[] = array($config_name, $mock_return_values[$i]);
}
$this->localeConfigManager
$this->typedConfigManager
->expects($this->any())
->method('hasConfigSchema')
->will($this->returnValueMap($map));
......
services:
locale.config.typed:
class: Drupal\locale\LocaleConfigManager
arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage', '@cache.discovery', '@config.factory', '@language_manager']
arguments: ['@config.storage', '@config.storage.installer', '@locale.storage', '@config.factory', '@config.typed', '@language_manager']
locale.storage:
class: Drupal\locale\StringDatabaseStorage
arguments: ['@database']
......
......@@ -7,8 +7,7 @@
namespace Drupal\locale;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -17,7 +16,14 @@
/**
* Manages localized configuration type plugins.
*/
class LocaleConfigManager extends TypedConfigManager {
class LocaleConfigManager {
/**
* A storage instance for reading configuration data.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $configStorage;
/**
* A storage instance for reading default configuration data.
......@@ -52,31 +58,36 @@ class LocaleConfigManager extends TypedConfigManager {
*/
protected $languageManager;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
/**
* Creates a new typed configuration manager.
*
* @param \Drupal\Core\Config\StorageInterface $configStorage
* The storage object to use for reading configuration data.
* @param \Drupal\Core\Config\StorageInterface $schemaStorage
* The storage object to use for reading schema data.
* @param \Drupal\Core\Config\StorageInterface $installStorage
* The storage object to use for reading default configuration
* data.
* @param \Drupal\locale\StringStorageInterface $localeStorage
* The locale storage to use for reading string translations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend to use for caching the definitions.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\language\ConfigurableLanguageManagerInterface
* The language manager.
*/
public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage, CacheBackendInterface $cache, ConfigFactoryInterface $config_factory, ConfigurableLanguageManagerInterface $language_manager) {
// Note we use the install storage for the parent constructor.
parent::__construct($configStorage, $schemaStorage, $cache);
public function __construct(StorageInterface $configStorage, StorageInterface $installStorage, StringStorageInterface $localeStorage, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config, ConfigurableLanguageManagerInterface $language_manager) {
$this->configStorage = $configStorage;
$this->installStorage = $installStorage;
$this->localeStorage = $localeStorage;
$this->configFactory = $config_factory;
$this->typedConfigManager = $typed_config;
$this->languageManager = $language_manager;
}
......@@ -95,11 +106,11 @@ public function get($name) {
$updated = $this->configStorage->read($name);
// We get only the data that didn't change from default.
$data = $this->compareConfigData($default, $updated);
$definition = $this->getDefinition($name);
$data_definition = $this->buildDataDefinition($definition, $data);
$definition = $this->typedConfigManager->getDefinition($name);
$data_definition = $this->typedConfigManager->buildDataDefinition($definition, $data);
// Unless the configuration has a explicit language code we assume English.
$langcode = isset($default['langcode']) ? $default['langcode'] : 'en';
$wrapper = new LocaleTypedConfig($data_definition, $name, $langcode, $this);
$wrapper = new LocaleTypedConfig($data_definition, $name, $langcode, $this, $this->typedConfigManager);
$wrapper->setValue($data);
return $wrapper;
}
......
......@@ -11,6 +11,7 @@
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\Config\Schema\Element;
use Drupal\Core\Config\Schema\ArrayElement;
use Drupal\Core\Config\TypedConfigManagerInterface;
/**
* Defines the locale configuration wrapper object.
......@@ -38,6 +39,13 @@ class LocaleTypedConfig extends Element {
*/
protected $localeConfig;
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
/**
* Constructs a configuration wrapper object.
*
......@@ -50,17 +58,18 @@ class LocaleTypedConfig extends Element {
* @param \Drupal\locale\LocaleConfigManager $localeConfig;
* The locale configuration manager object.
*/
public function __construct(DataDefinitionInterface $definition, $name, $langcode, LocaleConfigManager $localeConfig) {
public function __construct(DataDefinitionInterface $definition, $name, $langcode, LocaleConfigManager $localeConfig, TypedConfigManagerInterface $typed_config) {
parent::__construct($definition, $name);
$this->langcode = $langcode;
$this->localeConfig = $localeConfig;
$this->typedConfigManager = $typed_config;
}
/**
* Gets wrapped typed config object.
*/
public function getTypedConfig() {
return $this->localeConfig->create($this->definition, $this->value);
return $this->typedConfigManager->create($this->definition, $this->value);
}
/**
......@@ -72,7 +81,7 @@ public function getTranslation($langcode) {
'target' => $langcode,
);
$data = $this->getElementTranslation($this->getTypedConfig(), $options);
return $this->localeConfig->create($this->definition, $data);
return $this->typedConfigManager->create($this->definition, $data);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment