Skip to content

Commit

Permalink
Merge pull request #363 from mpalourdio/files
Browse files Browse the repository at this point in the history
Prevent Zend\Form\Element\File types inherit of StringLength validator...
  • Loading branch information
Ocramius committed Jan 4, 2015
2 parents e1855a6 + 54b8800 commit 49ed811
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions tests/DoctrineORMModuleTest/Assets/Entity/FormEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 16 additions & 0 deletions tests/DoctrineORMModuleTest/Form/AnnotationBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 49ed811

Please sign in to comment.