Skip to content

Commit 0d0a7ca

Browse files
authored
Merge pull request #52 from collecthor/fix-boolean-locale-fallback
fix: boolean variable displayvalue fallback to default locale
2 parents 290805a + 10033e4 commit 0d0a7ca

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"require": {
3737
"php": ">= 8.1",
38-
"collecthor/data-interfaces": ">= 5.2"
38+
"collecthor/data-interfaces": "5.2.*"
3939
},
4040
"config": {
4141
"allow-plugins": {

src/Variables/BooleanVariable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ public function getDisplayValue(RecordInterface $record, ?string $locale = 'defa
6565
return new StringValue((string) $result->getRawValue());
6666
} else {
6767
if ($result->getRawValue()) {
68-
return new StringValue($this->trueLabels[$locale]);
68+
return new StringValue($this->trueLabels[$locale] ?? $this->trueLabels['default']);
6969
} else {
70-
return new StringValue($this->falseLabels[$locale]);
70+
return new StringValue($this->falseLabels[$locale] ?? $this->falseLabels['default']);
7171
}
7272
}
7373
}

tests/Variables/BooleanVariableTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,25 @@ public function testNullValue(): void
141141

142142
self::assertInstanceOf(MissingBooleanValue::class, $value);
143143
}
144+
145+
public function testFallbackToDefaultLocale(): void
146+
{
147+
$subject = new BooleanVariable(
148+
"test",
149+
[],
150+
[
151+
"default" => "true",
152+
"nl" => "waar",
153+
],
154+
[
155+
"default" => "false",
156+
"nl" => "onwaar",
157+
],
158+
['path']
159+
);
160+
161+
$record = new ArrayRecord(['path' => true], 1, new \DateTime(), new \DateTime());
162+
self::assertSame("true", $subject->getDisplayValue($record)->getRawValue());
163+
self::assertSame("true", $subject->getDisplayValue($record, 'fakeLocale')->getRawValue());
164+
}
144165
}

0 commit comments

Comments
 (0)