[DoctrineBridge] Fix required guess of boolean fields

This commit is contained in:
Jáchym Toušek 2015-10-20 23:50:39 +02:00 committed by Fabien Potencier
parent d0e88caacb
commit b21d498fd3
1 changed files with 18 additions and 17 deletions

View File

@ -12,8 +12,9 @@
namespace Symfony\Bridge\Doctrine\Form;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as LegacyMappingException;
use Symfony\Component\Form\FormTypeGuesserInterface;
use Symfony\Component\Form\Guess\Guess;
@ -52,28 +53,28 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
}
switch ($metadata->getTypeOfField($property)) {
case 'array':
case Type::TARRAY:
return new TypeGuess('collection', array(), Guess::MEDIUM_CONFIDENCE);
case 'boolean':
case Type::BOOLEAN:
return new TypeGuess('checkbox', array(), Guess::HIGH_CONFIDENCE);
case 'datetime':
case Type::DATETIME:
case Type::DATETIMETZ:
case 'vardatetime':
case 'datetimetz':
return new TypeGuess('datetime', array(), Guess::HIGH_CONFIDENCE);
case 'date':
case Type::DATE:
return new TypeGuess('date', array(), Guess::HIGH_CONFIDENCE);
case 'time':
case Type::TIME:
return new TypeGuess('time', array(), Guess::HIGH_CONFIDENCE);
case 'decimal':
case 'float':
case Type::DECIMAL:
case Type::FLOAT:
return new TypeGuess('number', array(), Guess::MEDIUM_CONFIDENCE);
case 'integer':
case 'bigint':
case 'smallint':
case Type::INTEGER:
case Type::BIGINT:
case Type::SMALLINT:
return new TypeGuess('integer', array(), Guess::MEDIUM_CONFIDENCE);
case 'string':
case Type::STRING:
return new TypeGuess('text', array(), Guess::MEDIUM_CONFIDENCE);
case 'text':
case Type::TEXT:
return new TypeGuess('textarea', array(), Guess::MEDIUM_CONFIDENCE);
default:
return new TypeGuess('text', array(), Guess::LOW_CONFIDENCE);
@ -96,7 +97,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
// Check whether the field exists and is nullable or not
if ($classMetadata->hasField($property)) {
if (!$classMetadata->isNullable($property)) {
if (!$classMetadata->isNullable($property) && Type::BOOLEAN !== $classMetadata->getTypeOfField($property)) {
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
}
@ -131,7 +132,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
return new ValueGuess($mapping['length'], Guess::HIGH_CONFIDENCE);
}
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}
@ -144,7 +145,7 @@ class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
{
$ret = $this->getMetadata($class);
if ($ret && $ret[0]->hasField($property) && !$ret[0]->hasAssociation($property)) {
if (in_array($ret[0]->getTypeOfField($property), array('decimal', 'float'))) {
if (in_array($ret[0]->getTypeOfField($property), array(Type::DECIMAL, Type::FLOAT))) {
return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE);
}
}