10000 [DoctrineBridge] Fix required guess of boolean fields by enumag · Pull Request #16302 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Fix required guess of boolean fields #16302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,28 +52,28 @@ public function guessType($class, $property)
}

switch ($metadata->getTypeOfField($property)) {
case 'array':
case Type::TARRAY:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add SIMPLE_ARRAY and JSON_ARRAY?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if they work as collection form type as well. So lets do that in another PR if necessary.

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':
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is here. There doesn't seem to be a corresponding type in Doctrine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Expand All @@ -95,7 +96,7 @@ public function guessRequired($class, $property)

// 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);
}

Expand Down Expand Up @@ -130,7 +131,7 @@ public function guessMaxLength($class, $property)
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);
}
}
Expand All @@ -143,7 +144,7 @@ public function guessPattern($class, $property)
{
$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);
}
}
Expand Down
0