diff --git a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php index 43eddba17f..7b47d9c484 100644 --- a/core/modules/workflows/src/Plugin/WorkflowTypeBase.php +++ b/core/modules/workflows/src/Plugin/WorkflowTypeBase.php @@ -281,18 +281,27 @@ public function getTransitions(array $transition_ids = NULL) { */ protected static function labelWeightMultisort($objects) { if (count($objects) > 1) { + // Separate weights, labels, and keys into arrays. $weights = $labels = []; $keys = array_keys($objects); foreach ($objects as $id => $object) { $weights[$id] = $object->weight(); $labels[$id] = $object->label(); } + // Sort weights, labels, and keys in the same order as each other. array_multisort( - $weights, SORT_NUMERIC, SORT_ASC, - $labels, SORT_NATURAL, SORT_ASC, + $weights, + SORT_NUMERIC, + SORT_ASC, + $labels, + SORT_NATURAL, + SORT_ASC, $keys ); + // Combine keys and weights to make sure the weights are keyed with the + // correct keys. $weights = array_combine($keys, $weights); + // Return the objects sorted by weight. return array_replace($weights, $objects); } return $objects;