-
Notifications
You must be signed in to change notification settings - Fork 6
/
Html.php
38 lines (34 loc) · 1.37 KB
/
Html.php
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
<?php
namespace mgcode\helpers;
use Yii;
class Html extends \yii\helpers\Html
{
/**
* Added possibility to disable label.
* @inheritdoc
*/
public static function checkbox($name, $checked = false, $options = [])
{
$options['checked'] = (bool) $checked;
$value = array_key_exists('value', $options) ? $options['value'] : '1';
if (isset($options['uncheck'])) {
// add a hidden field so that if the checkbox is not selected, it still submits a value
$hidden = static::hiddenInput($name, $options['uncheck']);
unset($options['uncheck']);
} else {
$hidden = '';
}
// Checks if label is enabled, by default: yes.
$enableLabel = isset($options['enableLabel']) ? (bool) $options['enableLabel'] : true;
unset($options['enableLabel']);
if (isset($options['label']) && $enableLabel) {
$label = $options['label'];
$labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : [];
unset($options['label'], $options['labelOptions']);
$content = static::label(static::input('checkbox', $name, $value, $options) . ' ' . $label, null, $labelOptions);
return $hidden . $content;
} else {
return $hidden . static::input('checkbox', $name, $value, $options);
}
}
}