If no data is set, the SIUnitType uses no prefix now.

This commit is contained in:
Jan Böhmer 2019-08-26 15:19:46 +02:00
parent 5cc08af7b6
commit d32ced7547

View file

@ -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']);