|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Integrations\Elementor\Defaults; |
|
4
|
|
|
|
|
5
|
|
|
use Elementor\Controls_Manager; |
|
6
|
|
|
use GeminiLabs\SiteReviews\Defaults\DefaultsAbstract; |
|
7
|
|
|
|
|
8
|
|
|
class ControlDefaults extends DefaultsAbstract |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* The values that should be constrained after sanitization is run. |
|
12
|
|
|
* This is done after $casts and $sanitize. |
|
13
|
|
|
*/ |
|
14
|
|
|
public array $enums = [ |
|
15
|
|
|
]; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The keys that should be mapped to other keys. |
|
19
|
|
|
* Keys are mapped before the values are normalized and sanitized. |
|
20
|
|
|
* Note: Mapped keys should not be included in the defaults! |
|
21
|
|
|
*/ |
|
22
|
|
|
public array $mapped = [ |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The values that should be sanitized. |
|
27
|
|
|
* This is done after $casts and before $enums. |
|
28
|
|
|
*/ |
|
29
|
|
|
public array $sanitize = [ |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
protected function defaults(): array |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
'description' => '', |
|
36
|
|
|
'label' => '', |
|
37
|
|
|
'type' => 'text', |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Finalize provided values, this always runs last. |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function finalize(array $values = []): array |
|
45
|
|
|
{ |
|
46
|
|
|
$types = [ |
|
47
|
|
|
'checkbox' => Controls_Manager::SWITCHER, |
|
48
|
|
|
'number' => Controls_Manager::NUMBER, |
|
49
|
|
|
'radio' => Controls_Manager::CHOOSE, |
|
50
|
|
|
'select' => Controls_Manager::SELECT2, |
|
51
|
|
|
'text' => Controls_Manager::TEXT, |
|
52
|
|
|
'textarea' => Controls_Manager::TEXTAREA, |
|
53
|
|
|
]; |
|
54
|
|
|
if (array_key_exists($values['type'], $types)) { |
|
55
|
|
|
$values['type'] = $types[$values['type']]; |
|
56
|
|
|
} |
|
57
|
|
|
if (Controls_Manager::SWITCHER === $values['type'] && !empty($values['options'])) { |
|
58
|
|
|
$values['type'] = 'multi_switcher'; |
|
59
|
|
|
} |
|
60
|
|
|
if (!in_array($values['type'], [ |
|
61
|
|
|
Controls_Manager::CHOOSE, |
|
62
|
|
|
Controls_Manager::COLOR, |
|
63
|
|
|
Controls_Manager::NUMBER, |
|
64
|
|
|
Controls_Manager::SWITCHER, |
|
65
|
|
|
]) && !isset($values['label_block'])) { |
|
66
|
|
|
$values['label_block'] = true; |
|
67
|
|
|
} |
|
68
|
|
|
if (Controls_Manager::SELECT2 === $values['type'] && !empty($values['placeholder'])) { |
|
69
|
|
|
$values['select2options'] ??= []; |
|
70
|
|
|
$values['select2options']['placeholder'] = $values['placeholder']; |
|
71
|
|
|
} |
|
72
|
|
|
if (Controls_Manager::SELECT2 === $values['type'] && !isset($values['options'])) { |
|
73
|
|
|
$values['type'] = 'select2_ajax'; |
|
74
|
|
|
} |
|
75
|
|
|
return $values; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|