summaryrefslogtreecommitdiff
path: root/inc/Form/Label.php
blob: c8a86261377938df658def82d5b8dd9b58f129f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace dokuwiki\Form;

/**
 * Class Label
 * @package dokuwiki\Form
 */
class Label extends Element {
    /**
     * @var string the actual label text
     */
    public $label = '';

    /**
     * Creates a new Label
     *
     * @param string $label
     */
    public function __construct($label) {
        parent::__construct('label');
        $this->label = $label;
    }

    /**
     * Get or set the element's label text
     *
     * @param null|string $value
     * @return string|$this
     */
    public function val($value = null) {
        if($value !== null) {
            $this->label = $value;
            return $this;
        }
        return $this->label;
    }

    /**
     * The HTML representation of this element
     *
     * @return string
     */
    public function toHTML() {
        return '<label ' . buildAttributes($this->attrs()) . '>' . hsc($this->label) . '</label>';
    }
}