Toggle.php
845 Bytes
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
<?php
namespace AC\Form\Element;
use AC\Form\Element;
use AC\View;
class Toggle extends Element {
/**
* @var boolean
*/
private $checked;
public function __construct( $name, $label, $checked = false, $value = null ) {
parent::__construct( $name, [] );
$this->set_label( $label );
$this->checked = (bool) $checked;
if ( $value ) {
$this->set_value( $value );
}
}
protected function get_type() {
return 'checkbox';
}
public function render() {
$view = new View( [
'id' => $this->get_name(),
'name' => $this->get_name(),
'label' => $this->get_label(),
'checked' => $this->checked,
'value' => $this->get_value(),
'attributes' => $this->get_attributes_as_string( $this->get_attributes() ),
] );
return $view->set_template( 'component/toggle-v2' )->render();
}
}