Skip to content

Commit

Permalink
Allow range constraint for ezinteger and ezfloat to have only one of …
Browse files Browse the repository at this point in the history
…min/max
  • Loading branch information
emodric committed Aug 19, 2015
1 parent 7fbeed1 commit 707a150
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
23 changes: 17 additions & 6 deletions Form/FieldTypeHandler/Float.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,25 @@ protected function buildFieldForm(

if ( !empty( $fieldDefinition->getValidatorConfiguration()['FloatValueValidator'] ) )
{
$rangeConstraints = array();

$min = $fieldDefinition->getValidatorConfiguration()['FloatValueValidator']['minFloatValue'];
$max = $fieldDefinition->getValidatorConfiguration()['FloatValueValidator']['maxFloatValue'];
$options['constraints'][] = new Assert\Range(
array(
'min' => $min,
'max' => $max,
)
);

if ( $min !== false )
{
$rangeConstraints['min'] = $min;
}

if ( $max !== false )
{
$rangeConstraints['max'] = $max;
}

if ( !empty( $rangeConstraints ) )
{
$options['constraints'][] = new Assert\Range( $rangeConstraints );
}
}

if ( !empty( $fieldDefinition->defaultValue ) )
Expand Down
23 changes: 17 additions & 6 deletions Form/FieldTypeHandler/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@ protected function buildFieldForm(

if ( !empty( $fieldDefinition->getValidatorConfiguration()['IntegerValueValidator'] ) )
{
$rangeConstraints = array();

$min = $fieldDefinition->getValidatorConfiguration()['IntegerValueValidator']['minIntegerValue'];
$max = $fieldDefinition->getValidatorConfiguration()['IntegerValueValidator']['maxIntegerValue'];
$options['constraints'][] = new Assert\Range(
array(
'min' => $min,
'max' => $max,
)
);

if ( $min !== false )
{
$rangeConstraints['min'] = $min;
}

if ( $max !== false )
{
$rangeConstraints['max'] = $max;
}

if ( !empty( $rangeConstraints ) )
{
$options['constraints'][] = new Assert\Range( $rangeConstraints );
}
}

$formBuilder->add( $fieldDefinition->identifier, 'integer', $options );
Expand Down

0 comments on commit 707a150

Please sign in to comment.