diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index 0fbeeed..a0bd01a 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -46,7 +46,7 @@ mapping: sequence: label: Sequence class: '\Drupal\Core\Config\Schema\Sequence' - definition_class: '\Drupal\Core\TypedData\ListDataDefinition' + definition_class: '\Drupal\Core\Config\Schema\SequenceDataDefinition' # Simple extended data types: diff --git a/core/lib/Drupal/Core/Config/Schema/Sequence.php b/core/lib/Drupal/Core/Config/Schema/Sequence.php index 7b98761..26dc1b8 100644 --- a/core/lib/Drupal/Core/Config/Schema/Sequence.php +++ b/core/lib/Drupal/Core/Config/Schema/Sequence.php @@ -2,8 +2,6 @@ namespace Drupal\Core\Config\Schema; -use Drupal\Core\TypedData\TypedDataInterface; - /** * Defines a configuration element of type Sequence. * @@ -18,17 +16,6 @@ class Sequence extends ArrayElement { /** * {@inheritdoc} */ - public function __construct($definition, $name = NULL, TypedDataInterface $parent = NULL) { - parent::__construct($definition, $name, $parent); - - if (!isset($this->definition['orderby'])) { - $this->definition['orderby'] = 'none'; - } - } - - /** - * {@inheritdoc} - */ protected function getElementDefinition($key) { $value = isset($this->value[$key]) ? $this->value[$key] : NULL; // @todo: Remove BC layer for sequence with hyphen in front. https://www.drupal.org/node/2444979 @@ -42,4 +29,20 @@ protected function getElementDefinition($key) { return $this->buildDataDefinition($definition, $value, $key); } + /** + * Gets the description of how the sequence should be sorted. + * + * @return string|null + * Describes how the sequence should be sorted. Either 'value', 'key' or + * NULL. NULL means that the schema does not describe how the sequence + * should be sorted. + */ + public function getOrderBy() { + $definition = $this->getDataDefinition(); + if ($definition instanceof SequenceDataDefinition) { + return $definition->getOrderBy(); + } + return NULL; + } + } diff --git a/core/lib/Drupal/Core/Config/Schema/SequenceDataDefinition.php b/core/lib/Drupal/Core/Config/Schema/SequenceDataDefinition.php new file mode 100644 index 0000000..6264825 --- /dev/null +++ b/core/lib/Drupal/Core/Config/Schema/SequenceDataDefinition.php @@ -0,0 +1,24 @@ +definition['orderby']) ? $this->definition['orderby'] : NULL; + } + +} diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index d0c89e9..33b9323 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -214,7 +214,7 @@ protected function castValue($key, $value) { if ($element instanceof Sequence) { // Apply any sorting defined on the schema. - switch ($element->getDataDefinition()['orderby']) { + switch ($element->getOrderBy()) { case 'key': ksort($value); break;