Support manual sorting in foreign language

Given: Website uses copy / free mode of localization.
       and Editor selects specific events to display.
Then:  Those events should be displayed as selected.

Before this change the sorting was applied on uid of objects,
which is the uid of default lanugage record. But editors might select
localized uids. Therefore a fallback is added in case no object was
found.

Relates: #8557
This commit is contained in:
Daniel Siepmann 2021-03-16 08:10:46 +01:00
parent 4a8abbe344
commit cf2b571fda
2 changed files with 15 additions and 0 deletions

View file

@ -795,4 +795,12 @@ class Event extends AbstractEntity
{
return $this->_languageUid;
}
/**
* @return int
*/
public function getLocalizedUid()
{
return $this->_localizedUid;
}
}

View file

@ -95,7 +95,14 @@ class EventRepository extends Repository
usort($result, function (Event $eventA, Event $eventB) use ($expectedSorting) {
$positionOfA = array_search($eventA->getUid(), $expectedSorting);
if ($positionOfA === false) {
$positionOfA = array_search($eventA->getLocalizedUid(), $expectedSorting);
}
$positionOfB = array_search($eventB->getUid(), $expectedSorting);
if ($positionOfB === false) {
$positionOfB = array_search($eventB->getLocalizedUid(), $expectedSorting);
}
return $positionOfA <=> $positionOfB;
});