diff --git a/core/core.services.yml b/core/core.services.yml index afccb31..4690799 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -308,9 +308,11 @@ services: arguments: ['@config.storage', 'config/schema'] config.typed: class: Drupal\Core\Config\TypedConfigManager - arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler'] + arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler', '@class_resolver'] tags: - { name: plugin_manager_cache_clear } + calls: + - [setValidationConstraintManager, ['@validation.constraint']] context.handler: class: Drupal\Core\Plugin\Context\ContextHandler arguments: ['@typed_data_manager'] diff --git a/core/lib/Drupal/Core/Config/Schema/Mapping.php b/core/lib/Drupal/Core/Config/Schema/Mapping.php index cf02dd4..8646c92 100644 --- a/core/lib/Drupal/Core/Config/Schema/Mapping.php +++ b/core/lib/Drupal/Core/Config/Schema/Mapping.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Config\Schema; +use Drupal\Core\TypedData\ComplexDataInterface; /** * Defines a mapping configuration element. @@ -20,7 +21,7 @@ * Read https://www.drupal.org/node/1905070 for more details about configuration * schema, types and type resolution. */ -class Mapping extends ArrayElement { +class Mapping extends ArrayElement implements ComplexDataInterface { /** * {@inheritdoc} @@ -31,4 +32,24 @@ protected function getElementDefinition($key) { return $this->buildDataDefinition($definition, $value, $key); } + /** + * {@inheritdoc} + */ + public function set($property_name, $value, $notify = TRUE) { + $this->value[$property_name] = $value; + // @todo notify? + return $this; + } + + public function getProperties($include_computed = FALSE) { + $properties = array(); + foreach (array_keys($this->value) as $name) { + $definition = $this->getElementDefinition($name); + if ($include_computed || !$definition->isComputed()) { + $properties[$name] = $this->get($name); + } + } + return $properties; + } + } diff --git a/core/lib/Drupal/Core/Config/Schema/Sequence.php b/core/lib/Drupal/Core/Config/Schema/Sequence.php index 0c0900a..9cf5186 100644 --- a/core/lib/Drupal/Core/Config/Schema/Sequence.php +++ b/core/lib/Drupal/Core/Config/Schema/Sequence.php @@ -6,6 +6,7 @@ */ namespace Drupal\Core\Config\Schema; +use Drupal\Core\TypedData\ListInterface; /** * Defines a configuration element of type Sequence. @@ -16,7 +17,7 @@ * Read https://www.drupal.org/node/1905070 for more details about configuration * schema, types and type resolution. */ -class Sequence extends ArrayElement { +class Sequence extends ArrayElement implements ListInterface { /** * {@inheritdoc} @@ -34,4 +35,79 @@ protected function getElementDefinition($key) { return $this->buildDataDefinition($definition, $value, $key); } + public function getItemDefinition() { + // @todo. + } + + /** + * {@inheritdoc} + */ + public function set($index, $value) { + $this->value[$index] = $value; + } + + /** + * {@inheritdoc} + */ + public function first() { + reset($this->value); + return current($this->value); + } + + /** + * {@inheritdoc} + */ + public function appendItem($value = NULL) { + $this->value[] = $value; + } + + /** + * {@inheritdoc} + */ + public function removeItem($index) { + unset($this->value[$index]); + } + + /** + * {@inheritdoc} + */ + public function filter($callback) { + return array_filter($this->value, $callback); + } + + /** + * {@inheritdoc} + */ + public function count() { + return count($this->value); + } + + /** + * {@inheritdoc} + */ + public function offsetExists($offset) { + return isset($this->value[$offset]); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($offset) { + return $this->get($offset); + } + + /** + * {@inheritdoc} + */ + public function offsetSet($offset, $value) { + return $this->set($offset, $value); + } + + /** + * {@inheritdoc} + */ + public function offsetUnset($offset) { + unset($this->elements[$offset]); + } + } diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index ca0eb50..d5b9f4b 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Schema\ConfigSchemaAlterException; use Drupal\Core\Config\Schema\ConfigSchemaDiscovery; +use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\TypedData\TypedDataManager; @@ -49,13 +50,18 @@ class TypedConfigManager extends TypedDataManager implements TypedConfigManagerI * The storage object to use for reading schema data * @param \Drupal\Core\Cache\CacheBackendInterface $cache * The cache backend to use for caching the definitions. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler. + * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver + * The class resolver. */ - public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler) { + public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage, CacheBackendInterface $cache, ModuleHandlerInterface $module_handler, ClassResolverInterface $class_resolver) { $this->configStorage = $configStorage; $this->schemaStorage = $schemaStorage; $this->setCacheBackend($cache, 'typed_config_definitions'); $this->alterInfo('config_schema_info'); $this->moduleHandler = $module_handler; + $this->classResolver = $class_resolver; } /** diff --git a/core/lib/Drupal/Core/TypedData/DataDefinition.php b/core/lib/Drupal/Core/TypedData/DataDefinition.php index 1ef7c49..6e6f461 100644 --- a/core/lib/Drupal/Core/TypedData/DataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/DataDefinition.php @@ -6,12 +6,16 @@ */ namespace Drupal\Core\TypedData; +use Drupal\Core\DependencyInjection\DependencySerializationTrait; /** * A typed data definition class for defining data based on defined data types. */ class DataDefinition implements DataDefinitionInterface, \ArrayAccess { + use DependencySerializationTrait; + use TypedDataTrait; + /** * The array holding values for all definition keys. * @@ -263,7 +267,7 @@ public function setSetting($setting_name, $value) { */ public function getConstraints() { $constraints = isset($this->definition['constraints']) ? $this->definition['constraints'] : array(); - $constraints += \Drupal::typedDataManager()->getDefaultConstraints($this); + $constraints += $this->getTypedDataManager()->getDefaultConstraints($this); return $constraints; } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index be5bcd4..d25f7c4 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -122,7 +122,10 @@ public function createDataDefinition($data_type) { throw new \InvalidArgumentException("Invalid data type '$data_type' has been given"); } $class = $type_definition['definition_class']; - return $class::createFromDataType($data_type); + $data_definition = $class::createFromDataType($data_type); + $data_definition->setTypedDataManager($this); + + return $data_definition; } /** diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index e34d375..15b3a08 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -7,6 +7,8 @@ system.site: uuid: type: string label: 'Site UUID' + constraints: + NotNull: [] name: type: label label: 'Site name'