xref: /dokuwiki/inc/Form/FieldsetOpenElement.php (revision 6fd0861fbb9ed43b45640925d9acfe3dba3aad7b)
164744a10SAndreas Gohr<?php
29d01c1d9SSatoshi Sahara
364744a10SAndreas Gohrnamespace dokuwiki\Form;
464744a10SAndreas Gohr
564744a10SAndreas Gohr/**
664744a10SAndreas Gohr * Class FieldsetOpenElement
764744a10SAndreas Gohr *
864744a10SAndreas Gohr * Opens a Fieldset with an optional legend
964744a10SAndreas Gohr *
1064744a10SAndreas Gohr * @package dokuwiki\Form
1164744a10SAndreas Gohr */
129d01c1d9SSatoshi Saharaclass FieldsetOpenElement extends TagOpenElement
139d01c1d9SSatoshi Sahara{
1464744a10SAndreas Gohr
1564744a10SAndreas Gohr    /**
1664744a10SAndreas Gohr     * @param string $legend
1764744a10SAndreas Gohr     * @param array $attributes
1864744a10SAndreas Gohr     */
19*6fd0861fSAndreas Gohr    public function __construct($legend='', $attributes = [])
209d01c1d9SSatoshi Sahara    {
2164744a10SAndreas Gohr        // this is a bit messy and we just do it for the nicer class hierarchy
2264744a10SAndreas Gohr        // the parent would expect the tag in $value but we're storing the
2364744a10SAndreas Gohr        // legend there, so we have to set the type manually
2464744a10SAndreas Gohr        parent::__construct($legend, $attributes);
2564744a10SAndreas Gohr        $this->type = 'fieldsetopen';
2664744a10SAndreas Gohr    }
2764744a10SAndreas Gohr
2864744a10SAndreas Gohr    /**
2964744a10SAndreas Gohr     * The HTML representation of this element
3064744a10SAndreas Gohr     *
3164744a10SAndreas Gohr     * @return string
3264744a10SAndreas Gohr     */
339d01c1d9SSatoshi Sahara    public function toHTML()
349d01c1d9SSatoshi Sahara    {
3564744a10SAndreas Gohr        $html = '<fieldset '.buildAttributes($this->attrs()).'>';
3664744a10SAndreas Gohr        $legend = $this->val();
3764744a10SAndreas Gohr        if ($legend) $html .= DOKU_LF.'<legend>'.hsc($legend).'</legend>';
3864744a10SAndreas Gohr        return $html;
3964744a10SAndreas Gohr    }
4064744a10SAndreas Gohr}
41