X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FCore%2FConfig%2FStorableConfigBase.php;h=bc81ab7cc1709367e514712fecd65aab8daf485d;hb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;hp=4b227c9efbdce2575527e3ccab85b7f4aa0fc264;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Core/Config/StorableConfigBase.php b/web/core/lib/Drupal/Core/Config/StorableConfigBase.php index 4b227c9ef..bc81ab7cc 100644 --- a/web/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/web/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -3,6 +3,8 @@ namespace Drupal\Core\Config; use Drupal\Core\Config\Schema\Ignore; +use Drupal\Core\Config\Schema\Sequence; +use Drupal\Core\Config\Schema\SequenceDataDefinition; use Drupal\Core\TypedData\PrimitiveInterface; use Drupal\Core\TypedData\Type\FloatInterface; use Drupal\Core\TypedData\Type\IntegerInterface; @@ -129,9 +131,7 @@ abstract class StorableConfigBase extends ConfigBase { */ protected function getSchemaWrapper() { if (!isset($this->schemaWrapper)) { - $definition = $this->typedConfigManager->getDefinition($this->name); - $data_definition = $this->typedConfigManager->buildDataDefinition($definition, $this->data); - $this->schemaWrapper = $this->typedConfigManager->create($data_definition, $this->data); + $this->schemaWrapper = $this->typedConfigManager->createFromNameAndData($this->name, $this->data); } return $this->schemaWrapper; } @@ -210,6 +210,29 @@ abstract class StorableConfigBase extends ConfigBase { foreach ($value as $nested_value_key => $nested_value) { $value[$nested_value_key] = $this->castValue($key . '.' . $nested_value_key, $nested_value); } + + if ($element instanceof Sequence) { + $data_definition = $element->getDataDefinition(); + if ($data_definition instanceof SequenceDataDefinition) { + // Apply any sorting defined on the schema. + switch ($data_definition->getOrderBy()) { + case 'key': + ksort($value); + break; + + case 'value': + // The PHP documentation notes that "Be careful when sorting + // arrays with mixed types values because sort() can produce + // unpredictable results". There is no risk here because + // \Drupal\Core\Config\StorableConfigBase::castValue() has + // already cast all values to the same type using the + // configuration schema. + sort($value); + break; + + } + } + } } return $value; }