bug #16302 [DoctrineBridge] Fix required guess of boolean fields (enumag)

This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #16302).

Discussion
----------

[DoctrineBridge] Fix required guess of boolean fields

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Commits
-------

b21d498 [DoctrineBridge] Fix required guess of boolean fields
This commit is contained in:
Fabien Potencier 2015-10-23 09:39:54 +02:00
commit 73d9dab69f
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);
}
}