@@ -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 );
0 commit comments