Skip to content

Commit

Permalink
FIX: Source locale indicator correction.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfendeksilverstripe committed Apr 5, 2024
1 parent 7bf314a commit b238283
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/Extension/FluentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use SilverStripe\ORM\Queries\SQLConditionGroup;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\ValidationException;
use SilverStripe\Security\Permission;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\HTML;
use TractorCow\Fluent\Extension\Traits\FluentObjectTrait;
Expand All @@ -48,6 +47,7 @@
*
* @template T of DataObject
* @extends DataExtension<T&static>
* @property DataObject|$this $owner
*/
class FluentExtension extends DataExtension
{
Expand Down Expand Up @@ -582,11 +582,11 @@ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)

// Apply substitutions
$localisedPredicate = str_replace($conditionSearch, $conditionReplace, $predicate);

if (empty($localisedPredicate)) {
continue;
}

$where[$index] = [
$localisedPredicate => $parameters
];
Expand Down Expand Up @@ -965,19 +965,27 @@ protected function getRecordLocale()
return Locale::getCurrentLocale();
}


/**
* Returns the source locale that will display the content for this record
*
* @return Locale|null
*/
public function getSourceLocale()
public function getSourceLocale(): ?Locale
{
$sourceLocale = $this->owner->getField('SourceLocale');
$owner = $this->owner;
$currentLocale = FluentState::singleton()->getLocale();

// We do not have a locale set, so we can't determine a source
if (!$currentLocale) {
return null;
}

$localeInformation = $owner->LocaleInformation($currentLocale);
$sourceLocale = $localeInformation->getSourceLocale();
if ($sourceLocale) {
return Locale::getByLocale($sourceLocale);
}
return Locale::getDefault();
return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extension/FluentVersionedExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testSourceLocaleIsCurrentWhenPageExistsInIt()
->setIsDomainMode(false);

// Read from the locale that the page exists in already
/** @var Page $page */
/** @var Page|FluentSiteTreeExtension $page */
$page = $this->objFromFixture(Page::class, 'home');

$this->assertEquals('en_NZ', $page->getSourceLocale()->Locale);
Expand Down

0 comments on commit b238283

Please sign in to comment.