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