Skip to content

Commit 757b640

Browse files
committed
update
1 parent 32c0a5a commit 757b640

File tree

11 files changed

+40
-29
lines changed

11 files changed

+40
-29
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use MintyPHP\Form\Checkbox;
66
use MintyPHP\Form\Checkboxes;
7-
use MintyPHP\Form\FormField as Base;
7+
use MintyPHP\Form\Field as Base;
88

9-
class FormField extends Base
9+
class Field extends Base
1010
{
1111
public function __construct()
1212
{

src/Checkboxes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use DOMElement;
66
use MintyPHP\Form\Validator\Validator;
77

8-
class Checkboxes implements FormControl
8+
class Checkboxes implements Control
99
{
1010
use HtmlElement;
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use MintyPHP\Form\Validator\Validator;
66

7-
interface FormControl
7+
interface Control
88
{
99
public function id(string $id): self;
1010
public function getId(): string;

src/Elements.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Elements
1414
];
1515

1616
/**
17-
* @param FormField[] $fields
17+
* @param Field[] $fields
1818
*/
1919
public static function form(array $fields = []): Form
2020
{
@@ -29,10 +29,10 @@ public static function form(array $fields = []): Form
2929
/**
3030
* @param Validator[] $validators
3131
*/
32-
public static function field(?FormControl $control = null, ?Label $label = null, array $validators = []): FormField
32+
public static function field(?Control $control = null, ?Label $label = null, array $validators = []): Field
3333
{
34-
/** @var FormField */
35-
$field = self::create('FormField');
34+
/** @var Field */
35+
$field = self::create('Field');
3636
if ($control) {
3737
$field->control($control);
3838
}
@@ -193,17 +193,17 @@ public static function label(string $caption = ''): Label
193193
return $label;
194194
}
195195

196-
public static function header(): FormHeader
196+
public static function header(): Header
197197
{
198-
/** @var FormHeader */
199-
$header = self::create('FormHeader');
198+
/** @var Header */
199+
$header = self::create('Header');
200200
return $header;
201201
}
202202

203-
public static function legend(): FormLegend
203+
public static function legend(): Legend
204204
{
205-
/** @var FormLegend */
206-
$legend = self::create('FormLegend');
205+
/** @var Legend */
206+
$legend = self::create('Legend');
207207
return $legend;
208208
}
209209

src/FormField.php renamed to src/Field.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
use DOMElement;
66
use MintyPHP\Form\Validator\Validator;
77

8-
class FormField
8+
class Field
99
{
1010
use HtmlElement;
1111

1212
protected ?Label $label = null;
13-
protected ?FormControl $control = null;
13+
protected ?Control $control = null;
1414
protected ?Error $error = null;
1515
/** @var Validator[] */
1616
protected array $validators = [];
@@ -57,13 +57,13 @@ public function label(Label $label): self
5757
return $this;
5858
}
5959

60-
public function control(FormControl $control): self
60+
public function control(Control $control): self
6161
{
6262
$this->control = $control;
6363
return $this;
6464
}
6565

66-
public function getControl(): ?FormControl
66+
public function getControl(): ?Control
6767
{
6868
return $this->control;
6969
}

src/Fieldset.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ class Fieldset
99
{
1010
use HtmlElement;
1111

12-
/** @var FormField[] */
12+
/** @var Field[] */
1313
protected array $fields = [];
14-
protected ?FormHeader $header = null;
14+
protected ?Legend $legend = null;
15+
protected ?Header $header = null;
1516

1617
public function __construct()
1718
{
1819
$this->tag('div');
1920
}
2021

21-
public function field(FormField $field): self
22+
public function field(Field $field): self
2223
{
2324
$this->fields[] = $field;
2425
return $this;
2526
}
2627

2728
/**
28-
* @param FormField[] $fields
29+
* @param Field[] $fields
2930
*/
3031
public function fields(array $fields): self
3132
{
@@ -35,7 +36,13 @@ public function fields(array $fields): self
3536
return $this;
3637
}
3738

38-
public function header(FormHeader $header): self
39+
public function legend(Legend $legend): self
40+
{
41+
$this->legend = $legend;
42+
return $this;
43+
}
44+
45+
public function header(Header $header): self
3946
{
4047
$this->header = $header;
4148
return $this;
@@ -107,6 +114,10 @@ public function addErrors(array $messages): void
107114
public function renderDom(\DOMDocument $doc): \DOMElement
108115
{
109116
$fieldset = $this->renderElement($doc);
117+
if ($this->legend) {
118+
$legendElement = $this->legend->renderDom($doc);
119+
$fieldset->appendChild($legendElement);
120+
}
110121
if ($this->header) {
111122
$headerElement = $this->header->renderDom($doc);
112123
$fieldset->appendChild($headerElement);

src/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function fieldsets(array $fieldsets): self
8585
return $this;
8686
}
8787

88-
public function field(FormField $field): self
88+
public function field(Field $field): self
8989
{
9090
$this->hideFieldsets = true;
9191
$fieldset = new Fieldset();
@@ -95,7 +95,7 @@ public function field(FormField $field): self
9595
}
9696

9797
/**
98-
* @param FormField[] $fields
98+
* @param Field[] $fields
9999
*/
100100
public function fields(array $fields): self
101101
{
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use DOMElement;
66

7-
class FormHeader
7+
class Header
88
{
99
use HtmlElement;
1010

src/Input.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use DOMElement;
66
use MintyPHP\Form\Validator\Validator;
77

8-
class Input implements FormControl
8+
class Input implements Control
99
{
1010
use HtmlElement;
1111

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use DOMElement;
66

7-
class FormLegend
7+
class Legend
88
{
99
use HtmlElement;
1010

0 commit comments

Comments
 (0)