@@ -62,9 +62,24 @@ public function interactWith(
62
62
63
63
$ submittedData = [];
64
64
$ prototype = $ form ->getConfig ()->getAttribute ('prototype ' );
65
+ $ askIfEntryNeedsToBeSubmitted = function ($ entryNumber ) use ($ helperSet , $ input , $ output ) {
66
+ return $ this ->askIfExistingEntryShouldBeAdded ($ helperSet , $ input , $ output , $ entryNumber );
67
+ };
65
68
66
- while ($ this ->askIfContinueToAdd ($ helperSet , $ input , $ output )) {
67
- $ submittedData [] = $ this ->formInteractor ->interactWith ($ prototype , $ helperSet , $ input , $ output );
69
+ foreach ((array ) $ form ->getData () as $ key => $ entryData ) {
70
+ $ this ->printEntryHeader ($ key , $ output );
71
+ $ prototype ->setData ($ entryData );
72
+
73
+ $ submittedEntry = $ this ->formInteractor ->interactWith ($ prototype , $ helperSet , $ input , $ output );
74
+ if (!$ form ->getConfig ()->getOption ('allow_delete ' ) || $ askIfEntryNeedsToBeSubmitted ($ key )) {
75
+ $ submittedData [] = $ submittedEntry ;
76
+ }
77
+ }
78
+
79
+ if ($ form ->getConfig ()->getOption ('allow_add ' )) {
80
+ while ($ this ->askIfContinueToAdd ($ helperSet , $ input , $ output )) {
81
+ $ submittedData [] = $ this ->formInteractor ->interactWith ($ prototype , $ helperSet , $ input , $ output );
82
+ }
68
83
}
69
84
70
85
return $ submittedData ;
@@ -117,4 +132,52 @@ private function printHeader(FormInterface $form, OutputInterface $output)
117
132
)
118
133
);
119
134
}
135
+
136
+ /**
137
+ * @param int $entryNumber
138
+ * @param OutputInterface $output
139
+ */
140
+ private function printEntryHeader ($ entryNumber , OutputInterface $ output )
141
+ {
142
+ $ output ->writeln (
143
+ strtr (
144
+ '<fieldset>Edit entry {entryNumber}</fieldset> ' ,
145
+ [
146
+ '{entryNumber} ' => $ entryNumber ,
147
+ ]
148
+ )
149
+ );
150
+ }
151
+
152
+ /**
153
+ * @param HelperSet $helperSet
154
+ * @param InputInterface $input
155
+ * @param OutputInterface $output
156
+ * @param int $entryNumber
157
+ *
158
+ * @return string
159
+ */
160
+ private function askIfExistingEntryShouldBeAdded (
161
+ HelperSet $ helperSet ,
162
+ InputInterface $ input ,
163
+ OutputInterface $ output ,
164
+ $ entryNumber
165
+ ) {
166
+ return $ this ->questionHelper ($ helperSet )->ask (
167
+ $ input ,
168
+ $ output ,
169
+ new ConfirmationQuestion (
170
+ Format::forQuestion (
171
+ strtr (
172
+ 'Add entry {entryNumber} to the submitted entries? ' ,
173
+ [
174
+ '{entryNumber} ' => $ entryNumber ,
175
+ ]
176
+ ),
177
+ 'y '
178
+ ),
179
+ true
180
+ )
181
+ );
182
+ }
120
183
}
0 commit comments