Skip to content

Commit

Permalink
Check if string length constraint exists before using
Browse files Browse the repository at this point in the history
  • Loading branch information
emodric committed Aug 19, 2015
1 parent 707a150 commit 57270c9
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions Form/FieldTypeHandler/TextLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@ protected function buildFieldForm(
{
$options = $this->getDefaultFieldOptions( $fieldDefinition, $languageCode, $content );

$minStringLength = $fieldDefinition->validatorConfiguration["StringLengthValidator"]["minStringLength"];
$maxStringLength = $fieldDefinition->validatorConfiguration["StringLengthValidator"]["maxStringLength"];
$lengthConstraints = array();

if ( $minStringLength !== false )
if ( !empty( $fieldDefinition->validatorConfiguration["StringLengthValidator"] ) )
{
$lengthConstraints["min"] = $minStringLength;
}
$lengthConstraints = array();

if ( $maxStringLength !== false )
{
$lengthConstraints["max"] = $maxStringLength;
}
$minStringLength = $fieldDefinition->validatorConfiguration["StringLengthValidator"]["minStringLength"];
$maxStringLength = $fieldDefinition->validatorConfiguration["StringLengthValidator"]["maxStringLength"];

if ( !empty( $lengthConstraints ) )
{
$options["constraints"][] = new Constraints\Length( $lengthConstraints );
if ( $minStringLength !== false )
{
$lengthConstraints["min"] = $minStringLength;
}

if ( $maxStringLength !== false )
{
$lengthConstraints["max"] = $maxStringLength;
}

if ( !empty( $lengthConstraints ) )
{
$options["constraints"][] = new Constraints\Length( $lengthConstraints );
}
}

$formBuilder->add( $fieldDefinition->identifier, "text", $options );
Expand Down

0 comments on commit 57270c9

Please sign in to comment.