Skip to content

Commit

Permalink
bug #3779 Fixed the PercentField options when creating new entities (…
Browse files Browse the repository at this point in the history
…javiereguiluz)

This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Fixed the PercentField options when creating new entities

Fixes #3736.

Commits
-------

adfff6e Fixed the PercentField options when creating new entities
  • Loading branch information
javiereguiluz committed Sep 20, 2020
2 parents 511a589 + adfff6e commit ae199e5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Field/Configurator/PercentConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public function supports(FieldDto $field, EntityDto $entityDto): bool

public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
{
if (null === $field->getValue()) {
return;
}

$scale = $field->getCustomOption(PercentField::OPTION_NUM_DECIMALS);
$symbol = $field->getCustomOption(PercentField::OPTION_SYMBOL);
$isStoredAsFractional = $field->getCustomOption(PercentField::OPTION_STORED_AS_FRACTIONAL);
$value = $field->getValue();

$field->setFormattedValue(sprintf('%s%s', $isStoredAsFractional ? 100 * $value : $value, $symbol));

$field->setFormTypeOptionIfNotSet('scale', $scale);
$field->setFormTypeOptionIfNotSet('symbol', $symbol);
$field->setFormTypeOptionIfNotSet('type', $isStoredAsFractional ? 'fractional' : 'integer');

if (null === $field->getValue()) {
return;
}

$value = $field->getValue();
$field->setFormattedValue(sprintf('%s%s', $isStoredAsFractional ? 100 * $value : $value, $symbol));
}
}

0 comments on commit ae199e5

Please sign in to comment.