Commit 973170d2 authored by catch's avatar catch

Issue #2271967 by Jose Reyero, alexpott, amitgoyal: Fixed and use...

Issue #2271967 by Jose Reyero, alexpott, amitgoyal: Fixed and use TypedConfigManagerInterface/TypedConfigManager.
parent 2abc33aa
......@@ -63,10 +63,10 @@ class Config extends StorableConfigBase {
* configuration data.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* An event dispatcher instance to use for configuration events.
* @param \Drupal\Core\Config\TypedConfigManager $typed_config
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager service.
*/
public function __construct($name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManager $typed_config) {
public function __construct($name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) {
$this->name = $name;
$this->storage = $storage;
$this->eventDispatcher = $event_dispatcher;
......
......@@ -57,7 +57,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......@@ -75,10 +75,10 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
* The configuration storage engine.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* An event dispatcher instance to use for configuration events.
* @param \Drupal\Core\Config\TypedConfigManager $typed_config
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
*/
public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManager $typed_config) {
public function __construct(StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) {
$this->storage = $storage;
$this->eventDispatcher = $event_dispatcher;
$this->typedConfigManager = $typed_config;
......
......@@ -36,7 +36,7 @@ class ConfigManager implements ConfigManagerInterface {
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......@@ -82,7 +82,7 @@ class ConfigManager implements ConfigManagerInterface {
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Drupal\Core\Config\TypedConfigManager $typed_config_manager
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* The typed config manager.
* @param \Drupal\Core\StringTranslation\TranslationManager $string_translation
* The string translation service.
......@@ -91,7 +91,7 @@ class ConfigManager implements ConfigManagerInterface {
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
*/
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManager $typed_config_manager, TranslationManager $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher) {
public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationManager $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher) {
$this->entityManager = $entity_manager;
$this->configFactory = $config_factory;
$this->typedConfigManager = $typed_config_manager;
......
......@@ -46,7 +46,7 @@ abstract class StorableConfigBase extends ConfigBase {
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......
......@@ -85,9 +85,7 @@ public function get($name) {
}
/**
* Overrides \Drupal\Core\TypedData\TypedDataManager::create()
*
* Fills in default type and does variable replacement.
* {@inheritdoc}
*/
public function create(array $definition, $value = NULL, $name = NULL, $parent = NULL) {
if (!isset($definition['type'])) {
......@@ -106,7 +104,11 @@ public function create(array $definition, $value = NULL, $name = NULL, $parent =
$definition['type'] = $this->replaceName($definition['type'], $replace);
}
// Create typed config object.
$wrapper = $this->createInstance($definition['type'], $definition, $name, $parent);
$wrapper = $this->createInstance($definition['type'], array(
'data_definition' => $definition,
'name' => $name,
'parent' => $parent,
));
if (isset($value)) {
$wrapper->setValue($value, FALSE);
}
......@@ -114,29 +116,32 @@ public function create(array $definition, $value = NULL, $name = NULL, $parent =
}
/**
* Overrides Drupal\Core\TypedData\TypedDataFactory::createInstance().
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = array(), $name = NULL, $parent = NULL) {
$type_definition = $this->getDefinition($plugin_id);
public function createInstance($data_type, array $configuration = array()) {
$data_definition = $configuration['data_definition'];
$type_definition = $this->getDefinition($data_type);
if (!isset($type_definition)) {
throw new \InvalidArgumentException(String::format('Invalid data type %plugin_id has been given.', array('%plugin_id' => $plugin_id)));
throw new \InvalidArgumentException(String::format('Invalid data type %plugin_id has been given.', array('%plugin_id' => $data_type)));
}
$configuration += $type_definition;
// Allow per-data definition overrides of the used classes, i.e. take over
// classes specified in the data definition.
$key = empty($configuration['list']) ? 'class' : 'list class';
if (isset($configuration[$key])) {
$class = $configuration[$key];
// classes specified in the type definition.
$data_definition += $type_definition;
$key = empty($data_definition['list']) ? 'class' : 'list class';
if (isset($data_definition[$key])) {
$class = $data_definition[$key];
}
elseif (isset($type_definition[$key])) {
$class = $type_definition[$key];
}
if (!isset($class)) {
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id));
throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $data_type));
}
return new $class($configuration, $name, $parent);
return new $class($data_definition, $configuration['name'], $configuration['parent']);
}
/**
......@@ -286,6 +291,8 @@ protected function replaceName($name, $data) {
*
* @param string $value
* Variable value to be replaced.
* @param mixed $data
* Configuration data for the element.
*
* @return string
* The replaced value if a replacement found or the original value if not.
......
......@@ -17,6 +17,58 @@
*/
Interface TypedConfigManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface {
/**
* Gets typed configuration data.
*
* @param string $name
* Configuration object name.
*
* @return \Drupal\Core\Config\Schema\Element
* Typed configuration element.
*/
public function get($name);
/**
* Instantiates a typed configuration object.
*
* @param string $data_type
* The data type, for which a typed configuration object should be
* instantiated.
* @param array $configuration
* The plugin configuration array, i.e. an array with the following keys:
* - data definition: The data definition array.
* - name: (optional) If a property or list item is to be created, the name
* of the property or the delta of the list item.
* - parent: (optional) If a property or list item is to be created, the
* parent typed data object implementing either the ListInterface or the
* ComplexDataInterface.
*
* @return \Drupal\Core\Config\Schema\Element
* The instantiated typed configuration object.
*/
public function createInstance($data_type, array $configuration = array());
/**
* Creates a new typed configuration object instance.
*
* @param array $definition
* The data definition of the typed data object
* @param mixed $value
* (optional) The data value. If set, it has to match one of the supported
* data type format as documented for the data type classes.
* @param string $name
* (optional) If a property or list item is to be created, the name of the
* property or the delta of the list item.
* @param mixed $parent
* (optional) If a property or list item is to be created, the parent typed
* data object implementing either the ListInterface or the
* ComplexDataInterface.
*
* @return \Drupal\Core\Config\Schema\Element
* The instantiated typed data object.
*/
public function create(array $definition, $value = NULL, $name = NULL, $parent = NULL);
/**
* Checks if the configuration schema with the given config name exists.
*
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\Config\ConfigImporterException;
use Drupal\Core\Config\ConfigImporter;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
......@@ -18,7 +19,6 @@
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -73,7 +73,7 @@ class ConfigSync extends FormBase {
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......@@ -106,14 +106,14 @@ class ConfigSync extends FormBase {
* Configuration manager.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator service.
* @param \Drupal\Core\Config\TypedConfigManager $typed_config
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config
* The typed configuration manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler
*/
public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManager $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
public function __construct(StorageInterface $sourceStorage, StorageInterface $targetStorage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, UrlGeneratorInterface $url_generator, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
$this->sourceStorage = $sourceStorage;
$this->targetStorage = $targetStorage;
$this->lock = $lock;
......
......@@ -11,7 +11,7 @@
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\Schema\ArrayElement;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
......@@ -31,7 +31,7 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......@@ -61,10 +61,10 @@ class ConfigMapperManager extends DefaultPluginManager implements ConfigMapperMa
* The language manager.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Config\TypedConfigManager $typed_config_manager
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* The typed config manager.
*/
public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManager $typed_config_manager, ThemeHandlerInterface $theme_handler) {
public function __construct(CacheBackendInterface $cache_backend, LanguageManagerInterface $language_manager, ModuleHandlerInterface $module_handler, TypedConfigManagerInterface $typed_config_manager, ThemeHandlerInterface $theme_handler) {
$this->typedConfigManager = $typed_config_manager;
// Look at all themes and modules.
......
......@@ -10,7 +10,7 @@
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\Schema\Element;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\BaseFormIdInterface;
use Drupal\Core\Form\FormBase;
......@@ -30,7 +30,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
/**
* The typed configuration manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......@@ -93,7 +93,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
/**
* Creates manage form object with string translation storage.
*
* @param \Drupal\Core\Config\TypedConfigManager $typed_config_manager
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
* The typed configuration manager.
* @param \Drupal\config_translation\ConfigMapperManagerInterface $config_mapper_manager
* The configuration mapper manager.
......@@ -102,7 +102,7 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke the alter hook.
*/
public function __construct(TypedConfigManager $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) {
public function __construct(TypedConfigManagerInterface $typed_config_manager, ConfigMapperManagerInterface $config_mapper_manager, StringStorageInterface $locale_storage, ModuleHandlerInterface $module_handler, ConfigurableLanguageManagerInterface $language_manager) {
$this->typedConfigManager = $typed_config_manager;
$this->configMapperManager = $config_mapper_manager;
$this->localeStorage = $locale_storage;
......
......@@ -29,14 +29,14 @@ class ConfigEntityMapperTest extends UnitTestCase {
/**
* The entity manager used for testing.
*
* @var \Drupal\Core\Config\TypedConfigManager|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
/**
* The entity instance used for testing.
*
* @var \Drupal\Core\Config\TypedConfigManager|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Entity\EntityInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entity;
......
......@@ -30,7 +30,7 @@ class ConfigMapperManagerTest extends UnitTestCase {
/**
* The typed configuration manager used for testing.
*
* @var \Drupal\Core\Config\TypedConfigManager|\PHPUnit_Framework_MockObject_MockObject
* @var \Drupal\Core\Config\TypedConfigManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $typedConfigManager;
......@@ -53,8 +53,7 @@ public function setUp() {
->with(Language::TYPE_INTERFACE)
->will($this->returnValue($language));
$this->typedConfigManager = $this->getMockBuilder('Drupal\Core\Config\TypedConfigManager')
->disableOriginalConstructor()
$this->typedConfigManager = $this->getMockBuilder('Drupal\Core\Config\TypedConfigManagerInterface')
->getMock();
$module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
......
......@@ -42,7 +42,7 @@ class LanguageConfigFactoryOverride implements LanguageConfigFactoryOverrideInte
/**
* The typed config manager.
*
* @var \Drupal\Core\Config\TypedConfigManager
* @var \Drupal\Core\Config\TypedConfigManagerInterface
*/
protected $typedConfigManager;
......
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