PluginProbe
Simple Analytics / 1.67
Simple Analytics v1.67
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / Settings / Blocks / Fields / Checkbox.php

Checkbox.php in Simple Analytics 1.67, at src/Settings/Blocks/Fields/Checkbox.php

72 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics\Settings\Blocks\Fields;
4
5 use SimpleAnalytics\Setting;
6 use SimpleAnalytics\Settings\Concerns\HasDocs;
7 use SimpleAnalytics\UI\LabelComponent;
8
9 class Checkbox extends Field
10 {
11 use HasDocs;
12
13 /**
14 * @var bool
15 */
16 protected $default = false;
17
18 public function getValueSanitizer(): callable
19 {
20 return 'absint';
21 }
22
23 public function getValueType(): string
24 {
25 return 'integer';
26 }
27
28 public function default(bool $value): self
29 {
30 $this->default = $value;
31
32 return $this;
33 }
34
35 public function render(): void
36 {
37 ?>
38 <div class="relative flex gap-x-3">
39 <div class="flex h-6 items-center">
40 <input
41 id="<?php
42 echo esc_attr($this->getKey());
43 ?>"
44 name="<?php
45 echo esc_attr($this->getKey());
46 ?>"
47 type="checkbox"
48 value="1"
49 class="h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"
50 <?php
51 if (Setting::boolean($this->getKey(), $this->default) === true) echo 'checked';
52 ?>
53 >
54 </div>
55 <div class="text-sm leading-6">
56 <?php
57 (new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))();
58 ?>
59
60 <?php
61 if ($this->description): ?>
62 <p class="text-gray-500">
63 <?php echo esc_html($this->description); ?>
64 </p>
65 <?php endif;
66 ?>
67 </div>
68 </div>
69 <?php
70 }
71 }
72