|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Modules\Html; |
|
4
|
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Helper; |
|
6
|
|
|
|
|
7
|
|
|
class SettingBuilder extends Builder |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @return void|string |
|
11
|
|
|
*/ |
|
12
|
|
|
public function buildFormElement() |
|
13
|
|
|
{ |
|
14
|
|
|
$method = Helper::buildMethodName($this->tag, 'buildForm'); |
|
15
|
|
|
return $this->$method().$this->buildAfter().$this->buildFieldDescription(); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @return string|void |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function buildAfter() |
|
22
|
|
|
{ |
|
23
|
|
|
if (!empty($this->args->after)) { |
|
24
|
|
|
return ' '.$this->args->after; |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return string|void |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function buildFieldDescription() |
|
32
|
|
|
{ |
|
33
|
|
|
if (!empty($this->args->description)) { |
|
34
|
|
|
return $this->p([ |
|
35
|
|
|
'class' => 'description', |
|
36
|
|
|
'text' => $this->args->description, |
|
37
|
|
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return string|void |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function buildFormInputChoices() |
|
45
|
|
|
{ |
|
46
|
|
|
$fields = []; |
|
47
|
|
|
$index = 0; |
|
48
|
|
|
foreach ($this->args->options as $value => $label) { |
|
49
|
|
|
$fields[] = $this->input([ |
|
50
|
|
|
'checked' => in_array($value, $this->args->cast('value', 'array')), |
|
51
|
|
|
'id' => Helper::ifTrue(!empty($this->args->id), $this->args->id.'-'.++$index), |
|
52
|
|
|
'label' => $label, |
|
53
|
|
|
'name' => $this->args->name, |
|
54
|
|
|
'type' => $this->args->type, |
|
55
|
|
|
'value' => $value, |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
return $this->div([ |
|
59
|
|
|
'class' => $this->args->class, |
|
60
|
|
|
'text' => implode('<br>', $fields), |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return string|void |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function buildFormTextarea() |
|
68
|
|
|
{ |
|
69
|
|
|
$textarea = $this->buildFormLabel().$this->buildDefaultElement( |
|
70
|
|
|
esc_html($this->args->cast('value', 'string')) |
|
71
|
|
|
); |
|
72
|
|
|
if (empty($this->args->tags)) { |
|
73
|
|
|
return $textarea; |
|
74
|
|
|
} |
|
75
|
|
|
$buttons = []; |
|
76
|
|
|
foreach ($this->args->tags as $tag => $label) { |
|
77
|
|
|
$buttons[] = $this->input([ |
|
78
|
|
|
'class' => 'button button-small', |
|
79
|
|
|
'data-tag' => $tag, |
|
80
|
|
|
'type' => 'button', |
|
81
|
|
|
'value' => $label, |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
$toolbar = $this->div([ |
|
85
|
|
|
'class' => 'quicktags-toolbar', |
|
86
|
|
|
'text' => implode('', $buttons), |
|
87
|
|
|
]); |
|
88
|
|
|
return $this->div([ |
|
89
|
|
|
'class' => 'glsr-template-editor', |
|
90
|
|
|
'text' => $textarea.$toolbar, |
|
91
|
|
|
]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function normalize(array $args, $type) |
|
98
|
|
|
{ |
|
99
|
|
|
if (class_exists($className = $this->getFieldClassName($type))) { |
|
100
|
|
|
$args = $className::merge($args, 'setting'); |
|
101
|
|
|
} |
|
102
|
|
|
return $args; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|