32
32
final class MakeForm extends AbstractMaker
33
33
{
34
34
private $ entityHelper ;
35
+ private $ boundEntityOrClass = true ;
35
36
36
37
public function __construct (DoctrineEntityHelper $ entityHelper )
37
38
{
@@ -57,8 +58,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma
57
58
if (null != $ input ->getArgument ('name ' ) && $ this ->entityHelper ->isDoctrineConnected ()) {
58
59
$ question = new Question ('Enter the class or entity name that the new form will be bound to (empty for none) ' );
59
60
$ question ->setAutocompleterValues ($ this ->entityHelper ->getEntitiesForAutocomplete ());
60
- //$entity = $io->choice("Enter the class or entity name that the new form will be bound to", $this->entityHelper->getEntitiesForAutocomplete(), 'none');
61
- $ entity = $ io ->askQuestion ($ question );
61
+ $ this ->boundEntityOrClass = $ io ->askQuestion ($ question );
62
62
}
63
63
}
64
64
@@ -70,25 +70,37 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
70
70
'Type '
71
71
);
72
72
73
- $ entityClassNameDetails = $ generator ->createClassNameDetails (
74
- $ formClassNameDetails ->getRelativeNameWithoutSuffix (),
75
- 'Entity \\'
76
- );
73
+ if (null === $ this ->boundEntityOrClass ) {
77
74
78
- $ entityClassExists = class_exists ($ entityClassNameDetails ->getFullName ());
75
+ $ generator ->generateClass (
76
+ $ formClassNameDetails ->getFullName (),
77
+ 'form/SimpleType.tpl.php ' ,
78
+ [ ]
79
+ );
79
80
80
- $ formFields = $ entityClassExists ? $ this -> entityHelper -> getFormFieldsFromEntity ( $ entityClassNameDetails -> getFullName ()) : [ ' field_name ' ];
81
+ } else {
81
82
82
- $ generator ->generateClass (
83
- $ formClassNameDetails ->getFullName (),
84
- 'form/Type.tpl.php ' ,
85
- [
86
- 'entity_class_exists ' => $ entityClassExists ,
87
- 'entity_full_class_name ' => $ entityClassNameDetails ->getFullName (),
88
- 'entity_class_name ' => $ entityClassNameDetails ->getShortName (),
89
- 'form_fields ' => $ formFields ,
90
- ]
91
- );
83
+ $ entityClassNameDetails = $ generator ->createClassNameDetails (
84
+ true == $ this ->boundEntityOrClass ? $ formClassNameDetails ->getRelativeNameWithoutSuffix () : $ this ->boundEntityOrClass ,
85
+ 'Entity \\'
86
+ );
87
+
88
+ $ entityClassExists = class_exists ($ entityClassNameDetails ->getFullName ());
89
+
90
+ $ formFields = $ entityClassExists ? $ this ->entityHelper ->getFormFieldsFromEntity ($ entityClassNameDetails ->getFullName ()) : ['field_name ' ];
91
+
92
+ $ generator ->generateClass (
93
+ $ formClassNameDetails ->getFullName (),
94
+ 'form/Type.tpl.php ' ,
95
+ [
96
+ 'entity_class_exists ' => $ entityClassExists ,
97
+ 'entity_full_class_name ' => $ entityClassNameDetails ->getFullName (),
98
+ 'entity_class_name ' => $ entityClassNameDetails ->getShortName (),
99
+ 'form_fields ' => $ formFields ,
100
+ ]
101
+ );
102
+
103
+ }
92
104
93
105
$ generator ->writeChanges ();
94
106
0 commit comments