1212namespace Symfony \Bridge \Doctrine \Form ;
1313
1414use Doctrine \Common \Persistence \ManagerRegistry ;
15- use Doctrine \ORM \Mapping \ClassMetadataInfo ;
1615use Doctrine \Common \Persistence \Mapping \MappingException ;
16+ use Doctrine \DBAL \Types \Type ;
17+ use Doctrine \ORM \Mapping \ClassMetadataInfo ;
1718use Doctrine \ORM \Mapping \MappingException as LegacyMappingException ;
1819use Symfony \Component \Form \FormTypeGuesserInterface ;
1920use Symfony \Component \Form \Guess \Guess ;
@@ -52,28 +53,28 @@ public function guessType($class, $property)
5253 }
5354
5455 switch ($ metadata ->getTypeOfField ($ property )) {
55- case ' array ' :
56+ case Type:: TARRAY :
5657 return new TypeGuess ('collection ' , array (), Guess::MEDIUM_CONFIDENCE );
57- case ' boolean ' :
58+ case Type:: BOOLEAN :
5859 return new TypeGuess ('checkbox ' , array (), Guess::HIGH_CONFIDENCE );
59- case 'datetime ' :
60+ case Type::DATETIME :
61+ case Type::DATETIMETZ :
6062 case 'vardatetime ' :
61- case 'datetimetz ' :
6263 return new TypeGuess ('datetime ' , array (), Guess::HIGH_CONFIDENCE );
63- case ' date ' :
64+ case Type:: DATE :
6465 return new TypeGuess ('date ' , array (), Guess::HIGH_CONFIDENCE );
65- case ' time ' :
66+ case Type:: TIME :
6667 return new TypeGuess ('time ' , array (), Guess::HIGH_CONFIDENCE );
67- case ' decimal ' :
68- case ' float ' :
68+ case Type:: DECIMAL :
69+ case Type:: FLOAT :
6970 return new TypeGuess ('number ' , array (), Guess::MEDIUM_CONFIDENCE );
70- case ' integer ' :
71- case ' bigint ' :
72- case ' smallint ' :
71+ case Type:: INTEGER :
72+ case Type:: BIGINT :
73+ case Type:: SMALLINT :
7374 return new TypeGuess ('integer ' , array (), Guess::MEDIUM_CONFIDENCE );
74- case ' string ' :
75+ case Type:: STRING :
7576 return new TypeGuess ('text ' , array (), Guess::MEDIUM_CONFIDENCE );
76- case ' text ' :
77+ case Type:: TEXT :
7778 return new TypeGuess ('textarea ' , array (), Guess::MEDIUM_CONFIDENCE );
7879 default :
7980 return new TypeGuess ('text ' , array (), Guess::LOW_CONFIDENCE );
@@ -96,7 +97,7 @@ public function guessRequired($class, $property)
9697
9798 // Check whether the field exists and is nullable or not
9899 if ($ classMetadata ->hasField ($ property )) {
99- if (!$ classMetadata ->isNullable ($ property )) {
100+ if (!$ classMetadata ->isNullable ($ property ) && Type:: BOOLEAN !== $ classMetadata -> getTypeOfField ( $ property ) ) {
100101 return new ValueGuess (true , Guess::HIGH_CONFIDENCE );
101102 }
102103
@@ -131,7 +132,7 @@ public function guessMaxLength($class, $property)
131132 return new ValueGuess ($ mapping ['length ' ], Guess::HIGH_CONFIDENCE );
132133 }
133134
134- if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (' decimal ' , ' float ' ))) {
135+ if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (Type:: DECIMAL , Type:: FLOAT ))) {
135136 return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
136137 }
137138 }
@@ -144,7 +145,7 @@ public function guessPattern($class, $property)
144145 {
145146 $ ret = $ this ->getMetadata ($ class );
146147 if ($ ret && $ ret [0 ]->hasField ($ property ) && !$ ret [0 ]->hasAssociation ($ property )) {
147- if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (' decimal ' , ' float ' ))) {
148+ if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (Type:: DECIMAL , Type:: FLOAT ))) {
148149 return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
149150 }
150151 }
0 commit comments