Skip to content

Commit 54f9db6

Browse files
committed
make addControl generic
1 parent e6d6500 commit 54f9db6

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/Form.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,12 @@ public function jsSuccess($success = 'Success', $subHeader = null, bool $useTemp
330330
/**
331331
* Add form control into current layout. If no layout, create one. If no model, create blank one.
332332
*
333-
* @param array<mixed>|Control $control
334-
* @param array<mixed> $fieldSeed
333+
* @template T of Control = Control
334+
*
335+
* @param array{class-string<T>}|T $control
336+
* @param array<mixed> $fieldSeed
337+
*
338+
* @return T
335339
*/
336340
public function addControl(string $name, $control = [], array $fieldSeed = []): Control
337341
{
@@ -374,7 +378,11 @@ public function addGroup($title = null)
374378
* 3. $f->type is converted into seed and evaluated
375379
* 4. lastly, falling back to Line, Dropdown (based on $reference and $enum)
376380
*
377-
* @param array<string, mixed> $controlSeed
381+
* @template T of Control
382+
*
383+
* @param array{class-string<T>}|T $controlSeed
384+
*
385+
* @return T
378386
*/
379387
public function controlFactory(Field $field, $controlSeed = []): Control
380388
{

src/Form/AbstractLayout.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ abstract class AbstractLayout extends View
2727
/** Links layout to owner Form. */
2828
public Form $form;
2929

30+
/**
31+
* @template T of Control
32+
*
33+
* @param T $control
34+
*
35+
* @return T
36+
*/
3037
protected function _addControl(Control $control, Field $field): Control
3138
{
3239
return $this->add($control, $this->template->hasTag($field->shortName) ? $field->shortName : null);
@@ -36,8 +43,12 @@ protected function _addControl(Control $control, Field $field): Control
3643
* Places element inside a layout somewhere. Should be called
3744
* through $form->addControl().
3845
*
39-
* @param array<mixed>|Control $control
40-
* @param array<mixed> $fieldSeed
46+
* @template T of Control = Control
47+
*
48+
* @param array{class-string<T>}|T $control
49+
* @param array<mixed> $fieldSeed
50+
*
51+
* @return T
4152
*/
4253
public function addControl(string $name, $control = [], array $fieldSeed = []): Control
4354
{

0 commit comments

Comments
 (0)