1<?php
2
3namespace dokuwiki\Form;
4
5/**
6 * Class FieldsetOpenElement
7 *
8 * Opens a Fieldset with an optional legend
9 *
10 * @package dokuwiki\Form
11 */
12class FieldsetOpenElement extends TagOpenElement
13{
14    /**
15     * @param string $legend
16     * @param array $attributes
17     */
18    public function __construct($legend = '', $attributes = [])
19    {
20        // this is a bit messy and we just do it for the nicer class hierarchy
21        // the parent would expect the tag in $value but we're storing the
22        // legend there, so we have to set the type manually
23        parent::__construct($legend, $attributes);
24        $this->type = 'fieldsetopen';
25    }
26
27    /**
28     * The HTML representation of this element
29     *
30     * @return string
31     */
32    public function toHTML()
33    {
34        $html = '<fieldset ' . buildAttributes($this->attrs()) . '>';
35        $legend = $this->val();
36        if ($legend) $html .= DOKU_LF . '<legend>' . hsc($legend) . '</legend>';
37        return $html;
38    }
39}
40