Skip to content

Commit

Permalink
|selected filter orders by the value of the select
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Valchev authored and bobdenotter committed Nov 17, 2020
1 parent 40c1761 commit 2f61a7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Twig/FieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ public function getSelected(Field\SelectField $field, $returnsingle = false, $re

$ids = $field->getValue();
// Find records by their respective ids
$records = $this->contentRepository->findBy(['id' => $ids]);
$records = collect($this->contentRepository->findBy(['id' => $ids]));

// Sort the results in the order of the $ids.
$order = array_flip($ids);
$records = $records->sortBy(function (Content $record) use ($order) {
return $order[$record->getId()];
})->toArray();

if ($returnsingle || (! $returnarray && $definition->get('multiple') === false)) {
return current($records);
Expand Down

0 comments on commit 2f61a7b

Please sign in to comment.