From 463f0c14692ec52612957c1fed5e824030741fb5 Mon Sep 17 00:00:00 2001 From: barw4 Date: Fri, 10 Apr 2020 13:54:50 +0200 Subject: [PATCH] EZP-31449: Adapted TranslatablePropertyTransformer to properly handle nulls --- .../Form/DataTransformer/TranslatablePropertyTransformer.php | 4 +--- .../DataTransformer/TranslatablePropertyTransformerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/Form/DataTransformer/TranslatablePropertyTransformer.php b/src/lib/Form/DataTransformer/TranslatablePropertyTransformer.php index d541eefe48..2db053c7cb 100644 --- a/src/lib/Form/DataTransformer/TranslatablePropertyTransformer.php +++ b/src/lib/Form/DataTransformer/TranslatablePropertyTransformer.php @@ -36,9 +36,7 @@ public function transform($valueAsHash) public function reverseTransform($value) { - if (!$value) { - return null; - } + $value = (false === $value || [] === $value) ? null : $value; return [$this->languageCode => $value]; } diff --git a/src/lib/Tests/Form/DataTransformer/TranslatablePropertyTransformerTest.php b/src/lib/Tests/Form/DataTransformer/TranslatablePropertyTransformerTest.php index 0dab27f1dc..81dae0d851 100644 --- a/src/lib/Tests/Form/DataTransformer/TranslatablePropertyTransformerTest.php +++ b/src/lib/Tests/Form/DataTransformer/TranslatablePropertyTransformerTest.php @@ -60,8 +60,8 @@ public function testReverseTransform($inputValue, $languageCode, $expected) public function reverseTransformProvider() { return [ - [false, 'fre-FR', null], - [null, 'fre-FR', null], + [false, 'fre-FR', ['fre-FR' => null]], + [null, 'fre-FR', ['fre-FR' => null]], ['français', 'fre-FR', ['fre-FR' => 'français']], ['english', 'eng-GB', ['eng-GB' => 'english']], ['norsk', 'nor-NO', ['nor-NO' => 'norsk']],