Skip to content

Commit 6dcf61e

Browse files
committed
Print counter in collection and update the readme
1 parent 0945b7c commit 6dcf61e

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ If the submitted data is invalid the command will fail.
126126

127127
- Provide example of stand-alone usage (no need to extend the command)
128128
- Maybe: provide a way to submit a form at once, possibly using a JSON-encoded array
129-
- Handle invalid form data (maybe in a loop)
130129
- Add more functional tests
131130
- Show form label of root form
132131
- Show nesting in form hierarchy using breadcrumbs
133-
- Show counter when looping through a collection form
134132
- When these things have been provided, release this as a package (or multiple packages for stand-alone use)

src/Bridge/Interaction/CollectionInteractor.php

+20-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function interactWith(
6969
};
7070

7171
foreach ((array) $form->getData() as $key => $entryData) {
72-
$this->printEntryHeader($key, $output);
72+
$this->printEditEntryHeader($key, $output);
7373
$prototype->setData($entryData);
7474

7575
$submittedEntry = $this->formInteractor->interactWith($prototype, $helperSet, $input, $output);
@@ -79,7 +79,9 @@ public function interactWith(
7979
}
8080

8181
if ($form->getConfig()->getOption('allow_add')) {
82+
$key = count($submittedData) - 1;
8283
while ($this->askIfContinueToAdd($helperSet, $input, $output)) {
84+
$this->printAddEntryHeader(++$key, $output);
8385
$submittedData[] = $this->formInteractor->interactWith($prototype, $helperSet, $input, $output);
8486
}
8587
}
@@ -139,7 +141,7 @@ private function printHeader(FormInterface $form, OutputInterface $output)
139141
* @param int $entryNumber
140142
* @param OutputInterface $output
141143
*/
142-
private function printEntryHeader($entryNumber, OutputInterface $output)
144+
private function printEditEntryHeader($entryNumber, OutputInterface $output)
143145
{
144146
$output->writeln(
145147
strtr(
@@ -151,6 +153,22 @@ private function printEntryHeader($entryNumber, OutputInterface $output)
151153
);
152154
}
153155

156+
/**
157+
* @param int $entryNumber
158+
* @param OutputInterface $output
159+
*/
160+
private function printAddEntryHeader($entryNumber, OutputInterface $output)
161+
{
162+
$output->writeln(
163+
strtr(
164+
'<fieldset>Add entry {entryNumber}</fieldset>',
165+
[
166+
'{entryNumber}' => $entryNumber,
167+
]
168+
)
169+
);
170+
}
171+
154172
/**
155173
* @param HelperSet $helperSet
156174
* @param InputInterface $input

0 commit comments

Comments
 (0)