Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Source locale lookup correction.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Jul 9, 2020
1 parent 79c248b commit cfc1925
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Model/RecordLocale.php
Expand Up @@ -351,14 +351,20 @@ public function getSourceLocale(): ?Locale
{
/** @var DataObject|FluentExtension $record */
$record = $this->getOriginalRecord();
$validationMethod = 'existsInLocale';

if ($record->existsInLocale($this->getLocale())) {
if ($record->hasExtension(FluentVersionedExtension::class)) {
$stage = Versioned::get_stage() ?: Versioned::DRAFT;
$validationMethod = $stage === Versioned::DRAFT ? 'isDraftedInLocale' : 'isPublishedInLocale';
}

if ($record->{$validationMethod}($this->getLocale())) {
return $this->getLocaleObject();
}

/** @var Locale $fallback */
foreach ($this->getLocaleObject()->Fallbacks() as $fallback) {
if (!$record->existsInLocale($fallback->Locale)) {
if (!$record->{$validationMethod}($fallback->Locale)) {
continue;
}

Expand Down

0 comments on commit cfc1925

Please sign in to comment.