Skip to content

Commit 839e5dc

Browse files
committed
Container::getControls() returns list instead of iterator with names (BC break)
1 parent 5336503 commit 839e5dc

2 files changed

Lines changed: 4 additions & 28 deletions

File tree

src/Forms/Container.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,12 @@ public function addComponent(
312312

313313

314314
/**
315-
* Iterates over all form controls.
316-
* @return iterable<Control>
315+
* Retrieves the entire hierarchy of form controls including nested.
316+
* @return list<Control>
317317
*/
318318
public function getControls(): iterable
319319
{
320-
return Nette\Utils\Iterables::repeatable(function () {
321-
foreach ($this->getComponentTree() as $component) {
322-
if ($component instanceof Control) {
323-
yield $component->getName() => $component;
324-
}
325-
}
326-
});
320+
return array_values(array_filter($this->getComponentTree(), fn($c) => $c instanceof Control));
327321
}
328322

329323

tests/Forms/Container.getControls().phpt

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

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

0 commit comments

Comments
 (0)