+
+ 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;
+
+ }
+ }
+ }