MinLength
and MaxLength
have been combined into just Length
in 2.3 and I don't have as copy of 2.1 or 2.2 up and running, but I checked the old 2.1 and 2.2 API and this should work for you.
// MyFormType.php
<?php
if (!empty($options['unique']) && $options['unique'] == 'some_variable') {
$event->getForm()->add($factory->createNamed('existing_field', 'number', null, array(
'label' => 'Number field',
'required' => true,
'max_length' => 6,
'constraints' => array(
new MinLength(array(
'limit' => 6,
'message' => 'This field must be atleast 6 characters long'
)),
new MaxLength(array(
'limit' => 6,
'message' => 'This field must be shorter than 6 characters'
)),
),
)));
} else {
$event->getForm()->add($factory->createNamed('existing_field', 'text', null, array(
'label' => 'Text field',
)));
}