Skip to content

Commit 282c6cb

Browse files
committed
Container::getControls() returns list instead of iterator with names (BC break)
1 parent f590c7f commit 282c6cb

2 files changed

Lines changed: 4 additions & 27 deletions

File tree

src/Forms/Container.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,13 @@ public function addComponent(
301301

302302

303303
/**
304-
* Iterates over all form controls.
304+
* Retrieves the entire hierarchy of form controls including nested.
305+
* @return list<Control>
305306
* @return iterable<Control>
306307
*/
307308
public function getControls(): iterable
308309
{
309-
return Nette\Utils\Iterables::repeatable(function () {
310-
foreach ($this->getComponentTree() as $component) {
311-
if ($component instanceof Control) {
312-
yield $component->getName() => $component;
313-
}
314-
}
315-
});
310+
return array_values(array_filter($this->getComponentTree(), fn($c) => $c instanceof Control));
316311
}
317312

318313

tests/Forms/Container.getControls().phpt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,4 @@ $form->addContainer('cont')
1515
->addText('name');
1616

1717
$controls = $form->getControls();
18-
19-
$names = $values = [];
20-
foreach ($controls as $name => $value) {
21-
$names[] = $name;
22-
$values[] = $value;
23-
}
24-
25-
Assert::same(['name', 'age', 'name'], $names);
26-
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);
27-
28-
// again
29-
$names = $values = [];
30-
foreach ($controls as $name => $value) {
31-
$names[] = $name;
32-
$values[] = $value;
33-
}
34-
35-
Assert::same(['name', 'age', 'name'], $names);
36-
Assert::same([$form['name'], $form['age'], $form['cont-name']], $values);
18+
Assert::same([$form['name'], $form['age'], $form['cont-name']], $controls);

0 commit comments

Comments
 (0)