diff --git a/src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php b/src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php index 999a874e..5f7b02be 100644 --- a/src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php +++ b/src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php @@ -340,6 +340,13 @@ public function handleValidatorField(EventInterface $event) $inputSpec['validators'][] = array('name' => 'Int'); break; case 'string': + $elementSpec = $event->getParam('elementSpec'); + if (isset($elementSpec['spec']['type']) && + in_array($elementSpec['spec']['type'], array('File', 'Zend\Form\Element\File')) + ) { + return; + } + if (isset($mapping['length'])) { $inputSpec['validators'][] = array( 'name' => 'StringLength', diff --git a/tests/DoctrineORMModuleTest/Assets/Entity/FormEntity.php b/tests/DoctrineORMModuleTest/Assets/Entity/FormEntity.php index 198e416e..b2d86e27 100644 --- a/tests/DoctrineORMModuleTest/Assets/Entity/FormEntity.php +++ b/tests/DoctrineORMModuleTest/Assets/Entity/FormEntity.php @@ -144,4 +144,12 @@ class FormEntity * @Form\Attributes({"type":"textarea"}) */ protected $specificAttributeType; + + /** + * @ORM\Column(type="string", length=256) + * @Form\Type("File") + * @ORM\JoinColumn(nullable=true) + * @Form\Options({"label":"Image"}) + */ + protected $image; } diff --git a/tests/DoctrineORMModuleTest/Form/AnnotationBuilderTest.php b/tests/DoctrineORMModuleTest/Form/AnnotationBuilderTest.php index 5ffa3a4d..61a32ba7 100644 --- a/tests/DoctrineORMModuleTest/Form/AnnotationBuilderTest.php +++ b/tests/DoctrineORMModuleTest/Form/AnnotationBuilderTest.php @@ -100,6 +100,22 @@ public function testEnsureCustomTypeOrAttributeTypeIsUsedInAnnotations() $this->assertTrue($userDefinedTypeOverridesListenerType); } + /** + * @link https://github.com/zendframework/zf2/issues/7096 + */ + public function testFileTypeDoesntGrabStringLengthValidator() + { + $validators = $this + ->builder + ->createForm(new FormEntity()) + ->getInputFilter() + ->get('image') + ->getValidatorChain() + ->getValidators(); + + $this->assertEquals(0, count($validators)); + } + /** * Ensure prefer_form_input_filter is set to true for the generated form */