From d32ced7547af136fd752d5a9a26f32e2d54f1cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 26 Aug 2019 15:19:46 +0200 Subject: [PATCH] If no data is set, the SIUnitType uses no prefix now. --- src/Form/Type/SIUnitType.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Form/Type/SIUnitType.php b/src/Form/Type/SIUnitType.php index fd6092ef..13ce0c42 100644 --- a/src/Form/Type/SIUnitType.php +++ b/src/Form/Type/SIUnitType.php @@ -117,7 +117,7 @@ class SIUnitType extends AbstractType implements DataMapperInterface if ($options['show_prefix']) { $builder->add('prefix', ChoiceType::class, [ - 'choices' => ['M' => 6, 'k' => 3, '' => 0, 'm' => -3 ] + 'choices' => ['M' => 6, 'k' => 3, '' => 0, 'm' => -3, 'ยต' => -6 ] ]); } @@ -143,14 +143,18 @@ class SIUnitType extends AbstractType implements DataMapperInterface */ public function mapDataToForms($viewData, $forms) { + $forms = iterator_to_array($forms); + if ($viewData === null) { + if (isset($forms['prefix'])) { + $forms['prefix']->setData(0); + } + return null; } $data = $this->si_formatter->convertValue($viewData); - $forms = iterator_to_array($forms); - if (isset($forms['prefix'])) { $forms['value']->setData($data["value"]); $forms['prefix']->setData($data['prefix_magnitude']);