@@ -50,8 +50,10 @@ public function interactWith(
5050 throw new CanNotInteractWithForm ('Expected a "collection" form ' );
5151 }
5252
53- $ data = $ form ->getData ();
54- if (!$ form ->getConfig ()->getOption ('allow_add ' ) && empty ($ data )) {
53+ $ config = $ form ->getConfig ();
54+ $ data = $ form ->getData () ?: $ config ->getEmptyData ();
55+
56+ if (!$ config ->getOption ('allow_add ' ) && empty ($ data )) {
5557 throw new FormNotReadyForInteraction (
5658 'The "collection" form should have the option "allow_add" or have existing entries '
5759 );
@@ -66,7 +68,7 @@ public function interactWith(
6668 $ this ->printHeader ($ form , $ output );
6769
6870 $ submittedData = [];
69- $ prototype = $ form -> getConfig () ->getAttribute ('prototype ' );
71+ $ prototype = $ config ->getAttribute ('prototype ' );
7072 $ originalData = $ prototype ->getData ();
7173
7274 $ askIfEntryNeedsToBeSubmitted = function ($ entryNumber ) use ($ helperSet , $ input , $ output ) {
@@ -78,12 +80,12 @@ public function interactWith(
7880 $ prototype ->setData ($ entryData );
7981
8082 $ submittedEntry = $ this ->formInteractor ->interactWith ($ prototype , $ helperSet , $ input , $ output );
81- if (!$ form -> getConfig () ->getOption ('allow_delete ' ) || $ askIfEntryNeedsToBeSubmitted ($ key )) {
83+ if (!$ config ->getOption ('allow_delete ' ) || $ askIfEntryNeedsToBeSubmitted ($ key )) {
8284 $ submittedData [] = $ submittedEntry ;
8385 }
8486 }
8587
86- if ($ form -> getConfig () ->getOption ('allow_add ' )) {
88+ if ($ config ->getOption ('allow_add ' )) {
8789 // reset the prototype
8890 $ prototype ->setData ($ originalData );
8991 $ key = count ($ submittedData ) - 1 ;
0 commit comments