From 57270c9984db58e3c0469ccf0597f368219f8a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edi=20Modri=C4=87?= Date: Wed, 19 Aug 2015 16:18:15 +0200 Subject: [PATCH] Check if string length constraint exists before using --- Form/FieldTypeHandler/TextLine.php | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Form/FieldTypeHandler/TextLine.php b/Form/FieldTypeHandler/TextLine.php index 9105554..209400a 100644 --- a/Form/FieldTypeHandler/TextLine.php +++ b/Form/FieldTypeHandler/TextLine.php @@ -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 );