12
12
namespace Symfony \Bridge \Doctrine \Form ;
13
13
14
14
use Doctrine \Common \Persistence \ManagerRegistry ;
15
- use Doctrine \ORM \Mapping \ClassMetadataInfo ;
16
15
use Doctrine \Common \Persistence \Mapping \MappingException ;
16
+ use Doctrine \DBAL \Types \Type ;
17
+ use Doctrine \ORM \Mapping \ClassMetadataInfo ;
17
18
use Doctrine \ORM \Mapping \MappingException as LegacyMappingException ;
18
19
use Symfony \Component \Form \FormTypeGuesserInterface ;
19
20
use Symfony \Component \Form \Guess \Guess ;
@@ -52,28 +53,28 @@ public function guessType($class, $property)
52
53
}
53
54
54
55
switch ($ metadata ->getTypeOfField ($ property )) {
55
- case ' array ' :
56
+ case Type:: TARRAY :
56
57
return new TypeGuess ('collection ' , array (), Guess::MEDIUM_CONFIDENCE );
57
- case ' boolean ' :
58
+ case Type:: BOOLEAN :
58
59
return new TypeGuess ('checkbox ' , array (), Guess::HIGH_CONFIDENCE );
59
- case 'datetime ' :
60
+ case Type::DATETIME :
61
+ case Type::DATETIMETZ :
60
62
case 'vardatetime ' :
61
- case 'datetimetz ' :
62
63
return new TypeGuess ('datetime ' , array (), Guess::HIGH_CONFIDENCE );
63
- case ' date ' :
64
+ case Type:: DATE :
64
65
return new TypeGuess ('date ' , array (), Guess::HIGH_CONFIDENCE );
65
- case ' time ' :
66
+ case Type:: TIME :
66
67
return new TypeGuess ('time ' , array (), Guess::HIGH_CONFIDENCE );
67
- case ' decimal ' :
68
- case ' float ' :
68
+ case Type:: DECIMAL :
69
+ case Type:: FLOAT :
69
70
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 :
73
74
return new TypeGuess ('integer ' , array (), Guess::MEDIUM_CONFIDENCE );
74
- case ' string ' :
75
+ case Type:: STRING :
75
76
return new TypeGuess ('text ' , array (), Guess::MEDIUM_CONFIDENCE );
76
- case ' text ' :
77
+ case Type:: TEXT :
77
78
return new TypeGuess ('textarea ' , array (), Guess::MEDIUM_CONFIDENCE );
78
79
default :
79
80
return new TypeGuess ('text ' , array (), Guess::LOW_CONFIDENCE );
@@ -96,7 +97,7 @@ public function guessRequired($class, $property)
96
97
97
98
// Check whether the field exists and is nullable or not
98
99
if ($ classMetadata ->hasField ($ property )) {
99
- if (!$ classMetadata ->isNullable ($ property )) {
100
+ if (!$ classMetadata ->isNullable ($ property ) && Type:: BOOLEAN !== $ classMetadata -> getTypeOfField ( $ property ) ) {
100
101
return new ValueGuess (true , Guess::HIGH_CONFIDENCE );
101
102
}
102
103
@@ -131,7 +132,7 @@ public function guessMaxLength($class, $property)
131
132
return new ValueGuess ($ mapping ['length ' ], Guess::HIGH_CONFIDENCE );
132
133
}
133
134
134
- if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (' decimal ' , ' float ' ))) {
135
+ if (in_array ($ ret [0 ]->getTypeOfField ($ property ), array (Type:: DECIMAL , Type:: FLOAT ))) {
135
136
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
136
137
}
137
138
}
@@ -144,7 +145,7 @@ public function guessPattern($class, $property)
144
145
{
145
146
$ ret = $ this ->getMetadata ($ class );
146
147
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 ))) {
148
149
return new ValueGuess (null , Guess::MEDIUM_CONFIDENCE );
149
150
}
150
151
}
0 commit comments