Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Apr 5, 2024
1 parent fa19f22 commit 02336e6
Showing 1 changed file with 6 additions and 45 deletions.
51 changes: 6 additions & 45 deletions src/Model/RecordLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,61 +387,22 @@ public function getSourceLocale(): ?Locale
return null;
}

$fallbackLocales = [];

foreach ($this->getLocaleObject()->Fallbacks() as $fallback) {
$fallbackLocale = $fallback->Locale;
$fallbackLocales[] = $fallbackLocale;

if (!$record->existsInLocale($fallbackLocale)) {
if (!$record->existsInLocale($fallback->Locale)) {
continue;
}

// We found a locale to fall back to, so this will be our source locale
return $fallback;
}

// This model allows fallback to any locale even bypassing the fallback rules,
// Noting here that we have another case here that isn't handled correctly
// In case this model allows fallback to any locale even bypassing the fallback rules,
// so we just need to find the most recently updated locale
// as that's the one which is going to be providing content
if ($inheritanceMode === FluentExtension::INHERITANCE_MODE_ANY) {
$lastEditedList = ArrayList::create();

/** @var RecordLocale $localeInformation */
foreach ($record->Locales() as $localeInformation) {
$locale = $localeInformation->getLocale();

// Ignore any fallback locales as we've already confirmed that none of these locales
// are acting as the source locale
if (in_array($locale, $fallbackLocales)) {
continue;
}

$localisedRecord = $localeInformation->getRecord();

// We don't have any localised data in this locale so this doesn't qualify as a potential source locale
if (!$localisedRecord) {
continue;
}

$data = ArrayData::create([
'Locale' => $locale,
'LastEdited' => $localisedRecord->LastEdited,
]);

$lastEditedList->push($data);
}

// We found at leadt one candidate for the source locale, let's pick the most recently updated one
if ($lastEditedList->count() > 0) {
$sortedLocales = $lastEditedList
->sort('LastEdited', 'DESC')
->column('Locale');
$mostRecentlyEditedLocale = array_shift($sortedLocales);

return Locale::getByLocale($mostRecentlyEditedLocale);
}
}
// This is what we call base record fallback
// It's technically possible to figure out which locale the content is coming from but
// displaying this information may actually be confusing so just displaying no source might be more helpful

return null;
}
Expand Down

0 comments on commit 02336e6

Please sign in to comment.