From a6a6b19c7439446349676f0f9d5a145c6eb77191 Mon Sep 17 00:00:00 2001 From: Lars Hoevenaar Date: Wed, 15 Dec 2021 17:56:51 +0100 Subject: [PATCH] sort content selection as shown in admin This sorting is also applied in the Sulu bundle. See [issue](https://github.com/sulu/sulu/pull/5873). --- Content/ContentTypeResolver/AccountSelectionResolver.php | 6 ++++++ Content/ContentTypeResolver/ContactSelectionResolver.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Content/ContentTypeResolver/AccountSelectionResolver.php b/Content/ContentTypeResolver/AccountSelectionResolver.php index a79f6b1..b5643ec 100644 --- a/Content/ContentTypeResolver/AccountSelectionResolver.php +++ b/Content/ContentTypeResolver/AccountSelectionResolver.php @@ -58,6 +58,12 @@ public function resolve($data, PropertyInterface $property, string $locale, arra $content[] = $this->accountSerializer->serialize($account->getEntity(), $locale, $serializationContext); } + $ids = $property->getValue(); + $idPositions = \array_flip($ids); + \usort($content, function($a, $b) use ($idPositions) { + return $idPositions[$a['id']] - $idPositions[$b['id']]; + }); + return new ContentView($content, ['ids' => $data]); } } diff --git a/Content/ContentTypeResolver/ContactSelectionResolver.php b/Content/ContentTypeResolver/ContactSelectionResolver.php index c909ec4..fa9669c 100644 --- a/Content/ContentTypeResolver/ContactSelectionResolver.php +++ b/Content/ContentTypeResolver/ContactSelectionResolver.php @@ -58,6 +58,12 @@ public function resolve($data, PropertyInterface $property, string $locale, arra $content[] = $this->contactSerializer->serialize($contact->getEntity(), $locale, $serializationContext); } + $ids = $property->getValue(); + $idPositions = \array_flip($ids); + \usort($content, function($a, $b) use ($idPositions) { + return $idPositions[$a['id']] - $idPositions[$b['id']]; + }); + return new ContentView($content, ['ids' => $data]); } }