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