summaryrefslogtreecommitdiffstats
path: root/vendor/ipl/html/src/FormElement/RadioOption.php
blob: 4968c35afc610ed3acff4cc8acdf9e2af431fd16 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php

namespace ipl\Html\FormElement;

use ipl\Html\Attributes;

class RadioOption
{
    /** @var string The default label class */
    public const LABEL_CLASS = 'radio-label';

    /** @var string|int|null Value of the option */
    protected $value;

    /** @var string Label of the option */
    protected $label;

    /** @var mixed Css class of the option's label */
    protected $labelCssClass = self::LABEL_CLASS;

    /** @var bool Whether the radio option is disabled */
    protected $disabled = false;

    /** @var Attributes */
    protected $attributes;

    /**
     * RadioOption constructor.
     *
     * @param string|int|null $value
     * @param string $label
     */
    public function __construct($value, string $label)
    {
        $this->value = $value === '' ? null : $value;
        $this->label = $label;
    }

    /**
     * Set the label of the option
     *
     * @param string $label
     *
     * @return $this
     */
    public function setLabel(string $label): self
    {
        $this->label = $label;

        return $this;
    }

    /**
     * Get the label of the option
     *
     * @return string
     */
    public function getLabel(): string
    {
        return $this->label;
    }

    /**
     * Get the value of the option
     *
     * @return string|int|null
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * Set css class to the option label
     *
     * @param string|string[] $labelCssClass
     *
     * @return $this
     */
    public function setLabelCssClass($labelCssClass): self
    {
        $this->labelCssClass = $labelCssClass;

        return $this;
    }

    /**
     * Get css class of the option label
     *
     * @return string|string[]
     */
    public function getLabelCssClass()
    {
        return $this->labelCssClass;
    }

    /**
     * Set whether to disable the option
     *
     * @param bool $disabled
     *
     * @return $this
     */
    public function setDisabled(bool $disabled = true): self
    {
        $this->disabled = $disabled;

        return $this;
    }

    /**
     * Get whether the option is disabled
     *
     * @return bool
     */
    public function isDisabled(): bool
    {
        return $this->disabled;
    }

    /**
     * Add the attributes
     *
     * @param Attributes $attributes
     *
     * @return $this
     */
    public function addAttributes(Attributes $attributes): self
    {
        $this->attributes = $attributes;

        return $this;
    }

    /**
     * Get the attributes
     *
     * @return Attributes
     */
    public function getAttributes(): Attributes
    {
        if ($this->attributes === null) {
            $this->attributes = new Attributes();
        }

        return $this->attributes;
    }
}