Skip to content

Commit a3eb55a

Browse files
committed
Container::getControls() returns list instead of iterator with names (BC break)
1 parent 2f562c1 commit a3eb55a

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
@@ -291,17 +291,12 @@ public function addComponent(
291291

292292

293293
/**
294-
* Iterates over all form controls.
294+
* Retrieves the entire hierarchy of form controls including nested.
295+
* @return list<Control>
295296
*/
296297
public function getControls(): iterable
297298
{
298-
return Nette\Utils\Iterables::repeatable(function () {
299-
foreach ($this->getComponentTree() as $component) {
300-
if ($component instanceof Control) {
301-
yield $component->getName() => $component;
302-
}
303-
}
304-
});
299+
return array_values(array_filter($this->getComponentTree(), fn($c) => $c instanceof Control));
305300
}
306301

307302

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)